예제 #1
0
        public async Task<IdentityUser> RegisterUserIfNotFound(User userModel)
        {
            if (await _userManager.FindByNameAsync(userModel.UserName) == null)
            {
                await RegisterUserAsync(userModel);
            }

            return await FindUserAsync(userModel);
        }
예제 #2
0
        private async Task<IdentityResult> RegisterUserAsync(User userModel)
        {
            var user = new IdentityUser
            {
                UserName = userModel.UserName
            };

            var result = await _userManager.CreateAsync(user, userModel.Password);
            return result;
        }
예제 #3
0
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });

            var userModel = new User
            {
                UserName = context.UserName,
                Password = context.Password
            };

            var user = await _authRepository.RegisterUserIfNotFound(userModel);
            if (user == null)
            {
                context.SetError("invalid_grant", "The user name or password is incorrect.");
                context.Rejected();
                return;
            }

            var identity = new ClaimsIdentity(context.Options.AuthenticationType);
            identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, user.Id));
            context.Validated(identity);
        }
예제 #4
0
 public async Task<IdentityUser> FindUserAsync(User userModel)
 {
     var user = await _userManager.FindAsync(userModel.UserName, userModel.Password);
     return user;
 }