当前位置: 首页>>代码示例>>C#>>正文


C# AuthRepository.FindUser方法代码示例

本文整理汇总了C#中AuthRepository.FindUser方法的典型用法代码示例。如果您正苦于以下问题:C# AuthRepository.FindUser方法的具体用法?C# AuthRepository.FindUser怎么用?C# AuthRepository.FindUser使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AuthRepository的用法示例。


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: GrantResourceOwnerCredentials

        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            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:tmonte,项目名称:iap-api,代码行数:20,代码来源:SimpleAuthorizationServerProvider.cs

示例13: GrantResourceOwnerCredentials

        /// <summary>
        /// Validates the username and password sent to the authorization server's token endpoint.  We will 
        /// use "AuthRepository" class and call "FindUser" to check if the user name and password are valid.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {

            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;
                }
                IList<string> roles = _repo.GetUserRoles(context.UserName);

                // If valid - create a "ClaimsIdentity" and pass authentication type to it.
                // In our case "bearer token"
                var identity = new ClaimsIdentity(context.Options.AuthenticationType);
                identity.AddClaim(new Claim(ClaimTypes.Name, context.UserName));
                //Add roles to claims identity to be used when authorizing 
                //Admin screens.
                foreach (string role in roles)
                {
                    identity.AddClaim(new Claim(ClaimTypes.Role, role));
                }



                // rolesForUser now has a list role classes.

                AuthenticationProperties properties = CreateProperties(user.UserName, Newtonsoft.Json.JsonConvert.SerializeObject(roles));

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



        }
开发者ID:wiechars,项目名称:NowManagementStudio,代码行数:46,代码来源:SimpleAuthorizationServerProvider.cs

示例14: GrantResourceOwnerCredentials

        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {

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

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

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

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

        }
开发者ID:ehsmohammadi,项目名称:BTE.RMS,代码行数:23,代码来源:AuthorizationServerProvider.cs

示例15: GetCurrentUserId

        private string GetCurrentUserId(string userName)
        {
            using (var authRepository = new AuthRepository())
            {
                var user = authRepository.FindUser(userName);
                if (user != null)
                {
                    return user.Id;
                }
            }

            return string.Empty;
        }
开发者ID:ankitvijay,项目名称:AngularJSAuthentication,代码行数:13,代码来源:PrimaryConnectivityHub.cs


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