• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# AuthRepository类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中AuthRepository的典型用法代码示例。如果您正苦于以下问题:C# AuthRepository类的具体用法?C# AuthRepository怎么用?C# AuthRepository使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



AuthRepository类属于命名空间,在下文中一共展示了AuthRepository类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ValidateClientAuthentication

        public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
        {
            string clientId = string.Empty;
            string clientSecret = string.Empty;
            Client client = null;

            if (!context.TryGetBasicCredentials(out clientId, out clientSecret))
            {
                context.TryGetFormCredentials(out clientId, out clientSecret);
            }

            if (context.ClientId == null)
            {
                //Remove the comments from the below line context.SetError, and invalidate context 
                //if you want to force sending clientId/secrects once obtain access tokens. 
                context.Validated();
                //context.SetError("invalid_clientId", "ClientId should be sent.");
                return Task.FromResult<object>(null);
            }

            using (AuthRepository _repo = new AuthRepository())
            {
                client = _repo.FindClient(context.ClientId);
            }

            if (client == null)
            {
                context.SetError("invalid_clientId", string.Format("Client '{0}' is not registered in the system.", context.ClientId));
                return Task.FromResult<object>(null);
            }

            if (client.ApplicationType == ApplicationTypes.NativeConfidential)
            {
                if (string.IsNullOrWhiteSpace(clientSecret))
                {
                    context.SetError("invalid_clientId", "Client secret should be sent.");
                    return Task.FromResult<object>(null);
                }
                else
                {
                    if (client.Secret != HashHelper.GetHash(clientSecret))
                    {
                        context.SetError("invalid_clientId", "Client secret is invalid.");
                        return Task.FromResult<object>(null);
                    }
                }
            }

            if (!client.Active)
            {
                context.SetError("invalid_clientId", "Client is inactive.");
                return Task.FromResult<object>(null);
            }

            context.OwinContext.Set<string>("as:clientAllowedOrigin", client.AllowedOrigin);
            context.OwinContext.Set<string>("as:clientRefreshTokenLifeTime", client.RefreshTokenLifeTime.ToString());

            context.Validated();
            return Task.FromResult<object>(null);
        }
开发者ID:FarajiA,项目名称:AspNetIdentity.WebApi,代码行数:60,代码来源:CustomOAuthProvider.cs


示例2: BaseController

 public BaseController()
 {
     db = new uPlayAgainContext();
     _log = LogManager.GetLogger("uPlayAgain");
     _repo = new AuthRepository();
     _userManager = new ApplicationUserManager(new UserStore<User>(db));
 }
开发者ID:pandazzurro,项目名称:uPlayAgain,代码行数:7,代码来源:BaseController.cs


示例3: CreateAsync

		public async Task CreateAsync(AuthenticationTokenCreateContext context) {
			var clientid = context.Ticket.Properties.Dictionary["as:client_id"];

			if (string.IsNullOrEmpty(clientid)) {
				return;
			}

			var refreshTokenId = Guid.NewGuid().ToString("n");

			using (AuthRepository repo = new AuthRepository()) {
				var refreshTokenLifeTime = context.OwinContext.Get<string>("as:clientRefreshTokenLifeTime");

				var token = new RefreshToken() {
					Id = Helper.GetHash(refreshTokenId),
					ClientId = clientid,
					Subject = context.Ticket.Identity.Name,
					IssuedUtc = DateTime.UtcNow,
					ExpiresUtc = DateTime.UtcNow.AddMinutes(Convert.ToDouble(refreshTokenLifeTime))
				};

				context.Ticket.Properties.IssuedUtc = token.IssuedUtc;
				context.Ticket.Properties.ExpiresUtc = token.ExpiresUtc;

				token.ProtectedTicket = context.SerializeTicket();

				var result = await repo.AddRefreshToken(token);

				if (result) {
					context.SetToken(refreshTokenId);
				}

			}
		}
开发者ID:kottt,项目名称:OAuthPrototype,代码行数:33,代码来源:SimpleRefreshTokenProvider.cs


示例4: GrantResourceOwnerCredentials

        //validate the username and password sent to the authorization server’s token endpoint
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {

            //To allow CORS on the token middleware provider
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });

            using (AuthRepository _repo = new AuthRepository())
            {
                IdentityUser user = await _repo.FindUser(context.UserName, context.Password);

                if (user == null)
                {
                    context.SetError("invalid_grant", "The user name or password is incorrect.");
                    return;
                }
            }

            var identity = new ClaimsIdentity(context.Options.AuthenticationType);
            identity.AddClaim(new Claim("sub", context.UserName));
            identity.AddClaim(new Claim("role", "user"));

            //generating the token
            context.Validated(identity);

        }
开发者ID:mgalpy,项目名称:AngularJSAuthentication_Workthrough,代码行数:26,代码来源:SimpleAuthorizationServerProvider.cs


示例5: GrantResourceOwnerCredentials

        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            var allowedOrigin = context.OwinContext.Get<string>("as:clientAllowedOrigin") ?? "*";

            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin });

            using (AuthRepository _repo = new AuthRepository())
            {
                IdentityUser user = await _repo.FindUser(context.UserName, context.Password);

                if (user == null)
                {
                    context.SetError("invalid_grant", "The user name or password is incorrect.");
                    return;
                }
            }

            var identity = new ClaimsIdentity(context.Options.AuthenticationType);
            identity.AddClaim(new Claim(ClaimTypes.Name, context.UserName));
            identity.AddClaim(new Claim("sub", context.UserName));
            identity.AddClaim(new Claim("role", "user"));

            var props = new AuthenticationProperties(new Dictionary<string, string>
            {
                {
                    "as:client_id",(context.ClientId == null) ? string.Empty : context.ClientId
                },
                {
                    "userName", context.UserName
                }
            });

            var ticket = new AuthenticationTicket(identity, props);
            context.Validated(ticket);
        }
开发者ID:cjcoughlan,项目名称:angular-exercise,代码行数:35,代码来源:SimpleAuthorizationServerProvider.cs


示例6: GrantResourceOwnerCredentials

        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {

            //context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
            IdentityUser user;
            using (var _repo = new AuthRepository())
            {
                user = await _repo.FindUser(context.UserName, context.Password);

                if (user == null)
                {
                    context.SetError("invalid_grant", "The user name or password is incorrect.");
                    return;
                }
            }

            var identity = new ClaimsIdentity(context.Options.AuthenticationType);
            identity.AddClaim(new Claim("sub", context.UserName));
            identity.AddClaim(new Claim("userId", user.Id));

            if (user.Id == "c417fc8e-5bae-410f-b2ee-463afe2fdeaa")
                identity.AddClaim(new Claim(ClaimTypes.Role, "Admin"));

            var props = new AuthenticationProperties(new Dictionary<string, string>
            {
                {
                    "userId", user.Id
                }
            });

            var ticket = new AuthenticationTicket(identity, props);
            context.Validated(ticket);

        }
开发者ID:SashaBezugliy,项目名称:WebAPI,代码行数:34,代码来源:SimpleAuthorizationServerProvider.cs


示例7: GrantResourceOwnerCredentials

        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            var  allowedOrigin = "*";
            ApplicationUser appUser = null;

            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin });

            using (AuthRepository _repo = new AuthRepository())
            {
                 appUser = await _repo.FindUser(context.UserName, context.Password);

                if (appUser == null)
                {
                    context.SetError("invalid_grant", "The user name or password is incorrect.");
                    return;
                }
            }

            var identity = new ClaimsIdentity(context.Options.AuthenticationType);
            identity.AddClaim(new Claim(ClaimTypes.Name, context.UserName));
            identity.AddClaim(new Claim(ClaimTypes.Role, "User"));
            identity.AddClaim(new Claim("PSK", appUser.PSK));

            var props = new AuthenticationProperties(new Dictionary<string, string>
                {
                    { 
                        "userName", context.UserName
                    }
                });

            var ticket = new AuthenticationTicket(identity, props);
            context.Validated(ticket);
        }
开发者ID:modulexcite,项目名称:AngularJSTwoFactorAuthentication,代码行数:33,代码来源:SimpleAuthorizationServerProvider.cs


示例8: GrantResourceOwnerCredentials

        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            var allowedOrigin = context.OwinContext.Get<string>("as:clientAllowedOrigin");

            if (allowedOrigin == null) allowedOrigin = AuthenticationServerConfig.AccessControlAllowOrigin;

            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin });

            using (AuthRepository repository = new AuthRepository())
            {
                UserIdentity user = await repository.FindUser(context.UserName, context.Password);

                if (user == null)
                {
                    context.SetError("invalid_grant", "Incorrect user name or password.");
                    return;
                }
                ClaimsIdentity oAuthIdentity = await repository.GenerateClaims(user, "JWT");

                var props = new AuthenticationProperties(new Dictionary<string, string>
                {
                    {
                        "as:client_id", context.ClientId ?? string.Empty
                    },
                    {
                        "userName", context.UserName
                    }
                });

                var ticket = new AuthenticationTicket(oAuthIdentity, props);
                context.Validated(ticket);
            }
        }
开发者ID:grayboneonline,项目名称:SaleAssistant,代码行数:33,代码来源:CustomOAuthProvider+.cs


示例9: GrantResourceOwnerCredentials

        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {

            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });

            List<string> roles = new List<string>();
            IdentityUser user = new IdentityUser();

            using (AuthRepository _repo = new AuthRepository())
            {
                user = await _repo.FindUser(context.UserName, context.Password);

                if (user == null)
                {
                    context.SetError("invalid_grant", "Потребителското име или паролата не са верни.");
                    return;
                }
                else
                {
                    roles = await _repo.GetRolesForUser(user.Id);
                }
            }

            var identity = new ClaimsIdentity(context.Options.AuthenticationType);
            identity.AddClaim(new Claim("sub", context.UserName));
            foreach (var item in roles)
            {
                identity.AddClaim(new Claim(ClaimTypes.Role, item));
            }

            context.Validated(identity);
            context.Response.Headers.Add("UserRoles", roles.ToArray());
        }
开发者ID:lachezar1990,项目名称:test8,代码行数:33,代码来源:SimpleAuthorizationServerProvider.cs


示例10: Get

        public async Task<Confirmed> Get(string id)
        {
           string uid = Encoding.ASCII.GetString(HttpServerUtility.UrlTokenDecode(id));
            Confirmed c = new Confirmed();
            string fullstring = Util.Decrypt(uid, true);
            int index = fullstring.IndexOf("{GreenTime}");
           string  UserName = fullstring.Substring(0, index);
            string Password = fullstring.Substring(index + 11);

            AuthContext context = new AuthContext();
           IdentityUser user = null;
          
            People ps = context.Peoples.Where(p => p.email == UserName).SingleOrDefault();
            ps.emailConfirmed = true;

            using (AuthRepository _repo = new AuthRepository())
            {

                user = await _repo.FindUser(UserName, Password);


                if (user != null)
                {
                    context.updatePeople(ps);
                    c.isConfirmed = true;

                    return c;
                }
            }
        
            return c;
        }
开发者ID:rchaudharymore,项目名称:pDotAngular,代码行数:32,代码来源:ConfirmEmailController.cs


示例11: GrantResourceOwnerCredentials

        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {

            //context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });

            var header = context.OwinContext.Response.Headers.SingleOrDefault(h => h.Key == "Access-Control-Allow-Origin");
            
            if (header.Equals(default(KeyValuePair<string, string[]>)))
            {
                context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
            }

            using (AuthRepository _repo = new AuthRepository())
            {
                IdentityUser user = await _repo.FindUser(context.UserName, context.Password);

                if (user == null)
                {
                    context.SetError("invalid_grant", "The user name or password is incorrect.");
                    return;
                }
            }

            var identity = new ClaimsIdentity(context.Options.AuthenticationType);
            identity.AddClaim(new Claim("sub", context.UserName));
            identity.AddClaim(new Claim("role", "user"));

            context.Validated(identity);

        }
开发者ID:amoreiram,项目名称:Terraba,代码行数:30,代码来源:SimpleAuthorizationServerProvider.cs


示例12: UserController

 public UserController(IUserService userService, ICommunicationService communicationService, ILoggerService loggerService)
 {
     this.userService = userService;
     this.communicationService = communicationService;
     this.loggerService = loggerService;
     _repo = new AuthRepository();
 }
开发者ID:akhilchaudhari,项目名称:RedCabs,代码行数:7,代码来源:UserController.cs


示例13: GrantResourceOwnerCredentials

   public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
   {
       string allowedOrigin = context.OwinContext.Get<string>("as:clientAllowedOrigin") ?? "*";
       context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new string[1]
       {
   allowedOrigin
       });
       using (AuthRepository authRepository = new AuthRepository())
       {
           IdentityUser user = await authRepository.FindUser(context.UserName, context.Password);
           if (user == null)
           {
               context.SetError("invalid_grant", "The user name or password is incorrect.");
               goto label_8;
           }
       }
       ClaimsIdentity identity = new ClaimsIdentity(context.Options.AuthenticationType);
       identity.AddClaim(new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name", context.UserName));
       identity.AddClaim(new Claim("http://schemas.microsoft.com/ws/2008/06/identity/claims/role", "user"));
       identity.AddClaim(new Claim("sub", context.UserName));
       AuthenticationProperties props = new AuthenticationProperties((IDictionary<string, string>)new Dictionary<string, string>()
 {
   {
     "as:client_id",
     context.ClientId == null ? string.Empty : context.ClientId
   },
   {
     "userName",
     context.UserName
   }
 });
       AuthenticationTicket ticket = new AuthenticationTicket(identity, props);
       context.Validated(ticket);
       label_8:;
   }
开发者ID:quangnc0503h,项目名称:ecommerce,代码行数:35,代码来源:SimpleAuthorizationServerProvider.cs


示例14: GrantResourceOwnerCredentials

        // Responsible for validating the username and password sent to the authorization server's token endpoint.
        // If credentials are valid, two claims ("sub", "role") are added and will be include in the signed token.
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            /* Allow CORS (Cross-Origin-Resource-Sharing) on the token middleware provider.
             * If not included, generating the token will fail when you try to call it from the browser.
             */
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });

            using (AuthRepository repo = new AuthRepository())
            {
                var user = await repo.FindUser(context.UserName, context.Password);
                if (user == null)
                {
                    context.SetError("invalid_grant", "The username or password is incorrect.");
                    return;
                }

                //var identity = new ClaimsIdentity(context.Options.AuthenticationType);
                //identity.AddClaim(new Claim("sub", context.UserName));
                //identity.AddClaim(new Claim("role", "user"));
                // Token generation happens behind the scenes here!!!
                //context.Validated(identity);

                ClaimsIdentity oAuthIdentity = await user.GenerateUserIdentityAsync(repo.UserManager, OAuthDefaults.AuthenticationType);
                AuthenticationProperties properties = CreateProperties(oAuthIdentity);
                AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, properties);
                context.Validated(ticket);
            }
        }
开发者ID:okusnadi,项目名称:personal-finance,代码行数:30,代码来源:SimpleAuthorizationServerProvider.cs


示例15: GrantResourceOwnerCredentials

 public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
 {
     context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
     IdentityUser user;
     using (AuthRepository _repo = new AuthRepository())
     {
          user = await _repo.FindUser(context.UserName, context.Password);
         if (user == null)
         {
             context.SetError("invalid_grant", "The user name or password is incorrect.");
             return;
         }
     }
     var identity = new ClaimsIdentity(context.Options.AuthenticationType);
     identity.AddClaim(new Claim("sub", context.UserName));
     identity.AddClaim(new Claim("role", "user"));
     Microsoft.Owin.Security.AuthenticationProperties properties = new Microsoft.Owin.Security.AuthenticationProperties(new Dictionary<string, string>
             {
                 { "userId", user.Id }
     
             });
     Microsoft.Owin.Security.AuthenticationTicket ticket = new Microsoft.Owin.Security.AuthenticationTicket(identity, properties);
     // the above didn't worked so working around for the same
     context.Validated(ticket);
    // context.Validated(identity);
 }
开发者ID:nautymanish,项目名称:Demo,代码行数:26,代码来源:SimpleAuthorizationServerProvider.cs


示例16: AccountController

    public AccountController()
    {
        _repo = new AuthRepository();
        _ctx = new AuthContext();

        UserStore<UserModel> userStore = new UserStore<UserModel>(_ctx);
        _userManager = new UserManager<UserModel>(userStore);

        _userBCA = new UserBusinessComponentAdapter();
    }
开发者ID:NicoVerbeeke,项目名称:EVA18-backend,代码行数:10,代码来源:AccountController.cs


示例17: ServiceUser

 public ServiceUser(
     UserRepository userRepo,
     RoleRepository roleRepo,
     AuthRepository authRepo,
     UnitOfWork unit)
     : base(unit)
 {
     this.user_repo = userRepo;
     this.role_repo = roleRepo;
     this.auth_repo = authRepo;
 }
开发者ID:zicjin,项目名称:Board,代码行数:11,代码来源:ServiceUser.cs


示例18: ServiceSeat

 public ServiceSeat(
     SeatHistoryRepository seathistRepo,
     SeatRepository seatRepo,
     AuthRepository authRepo,
     UserRepository userRepo,
     FolderRepository folderRepo,
     UnitOfWork unit)
     : base(unit)
 {
     this.seathist_repo = seathistRepo;
     this.seat_repo = seatRepo;
     this.auth_repo = authRepo;
     this.user_repo = userRepo;
     this.folder_repo = folderRepo;
 }
开发者ID:zicjin,项目名称:Board,代码行数:15,代码来源:ServiceSeat.cs


示例19: ReceiveAsync

		public async Task ReceiveAsync(AuthenticationTokenReceiveContext context) {

			var allowedOrigin = context.OwinContext.Get<string>("as:clientAllowedOrigin");
			context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin });

			string hashedTokenId = Helper.GetHash(context.Token);

			using (AuthRepository repo = new AuthRepository()) {
				var refreshToken = await repo.FindRefreshToken(hashedTokenId);

				if (refreshToken != null) {
					//Get protectedTicket from refreshToken class
					context.DeserializeTicket(refreshToken.ProtectedTicket);
					var result = await repo.RemoveRefreshToken(hashedTokenId);
				}
			}
		}
开发者ID:kottt,项目名称:OAuthPrototype,代码行数:17,代码来源:SimpleRefreshTokenProvider.cs


示例20: ValidateClientAuthentication

 public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
 {
     string clientId = string.Empty;
     string clientSecret = string.Empty;
     Client client = (Client)null;
     if (!context.TryGetBasicCredentials(out clientId, out clientSecret))
         context.TryGetFormCredentials(out clientId, out clientSecret);
     if (context.ClientId == null)
     {
         context.Validated();
         return (Task)Task.FromResult<object>((object)null);
     }
     using (AuthRepository authRepository = new AuthRepository())
         client = authRepository.FindClient(context.ClientId);
     if (client == null)
     {
         context.SetError("invalid_clientId", string.Format("Client '{0}' is not registered in the system.", (object)context.ClientId));
         return (Task)Task.FromResult<object>((object)null);
     }
     if (client.ApplicationType == ApplicationTypes.NativeConfidential)
     {
         if (string.IsNullOrEmpty(clientSecret))
         {
             context.SetError("invalid_clientId", "Client secret should be sent.");
             return (Task)Task.FromResult<object>((object)null);
         }
         if (client.Secret != Helper.GetHash(clientSecret))
         {
             context.SetError("invalid_clientId", "Client secret is invalid.");
             return (Task)Task.FromResult<object>((object)null);
         }
     }
     if (!client.Active)
     {
         context.SetError("invalid_clientId", "Client is inactive.");
         return (Task)Task.FromResult<object>((object)null);
     }
     context.OwinContext.Set<string>("as:clientAllowedOrigin", client.AllowedOrigin);
     context.OwinContext.Set<string>("as:clientRefreshTokenLifeTime", client.RefreshTokenLifeTime.ToString());
     context.Validated();
     return (Task)Task.FromResult<object>((object)null);
 }
开发者ID:quangnc0503h,项目名称:ecommerce,代码行数:42,代码来源:SimpleAuthorizationServerProvider.cs



注:本文中的AuthRepository类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# AuthType类代码示例发布时间:2022-05-24
下一篇:
C# AuthContext类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap