Academatica.Api/Academatica.Api.Auth/AuthManagement/ResourceOwnerPasswordValidator.cs
/// <summary>
/// Validates the resource owner password credential
/// </summary>
/// <param name="context">The context.</param>
/// <returns></returns>
Validates the resource owner password credential
Validates the resource owner password credential
public virtual async Task ValidateAsync(ResourceOwnerPasswordValidationContext context)
        {
            var user = await _userManager.FindByEmailAsync(context.UserName);
            if (user != null)
            {
                var result = await _signInManager.CheckPasswordSignInAsync(user, context.Password, true);
                if (result.Succeeded)
                {
                    var sub = await _userManager.GetUserIdAsync(user);
                    _logger.LogInformation("Credentials validated for username: {username}", context.UserName);
                    await _events.RaiseAsync(new UserLoginSuccessEvent(context.UserName, sub, context.UserName, interactive: false));
                    context.Result = new GrantValidationResult(sub, AuthenticationMethods.Password);
                    return;
                }
                else if (result.IsLockedOut)
                {
                    _logger.LogInformation("Authentication failed for username: {username}, reason: locked out", context.UserName);
                    await _events.RaiseAsync(new UserLoginFailureEvent(context.UserName, "locked out", interactive: false));
                }
                else if (result.IsNotAllowed)
                {
                    _logger.LogInformation("Authentication failed for username: {username}, reason: not allowed", context.UserName);
                    await _events.RaiseAsync(new UserLoginFailureEvent(context.UserName, "not allowed", interactive: false));
                }
                else
                {
                    _logger.LogInformation("Authentication failed for username: {username}, reason: invalid credentials", context.UserName);
                    await _events.RaiseAsync(new UserLoginFailureEvent(context.UserName, "invalid credentials", interactive: false));
                }
            }
            else
            {
                _logger.LogInformation("No user found matching username: {username}", context.UserName);
                await _events.RaiseAsync(new UserLoginFailureEvent(context.UserName, "invalid username", interactive: false));
            }
            context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant);
        }
public virtual async Task ValidateAsync ( ResourceOwnerPasswordValidationContext context ) { var user = await _userManager . FindByEmailAsync ( context . UserName ) ; if ( user != null ) { var result = await _signInManager . CheckPasswordSignInAsync ( user , context . Password , true ) ; if ( result . Succeeded ) { var sub = await _userManager . GetUserIdAsync ( user ) ; _logger . LogInformation ( " " , context . UserName ) ; await _events . RaiseAsync ( new UserLoginSuccessEvent ( context . UserName , sub , context . UserName , interactive : false ) ) ; context . Result = new GrantValidationResult ( sub , AuthenticationMethods . Password ) ; return ; } else if ( result . IsLockedOut ) { _logger . LogInformation ( " " , context . UserName ) ; await _events . RaiseAsync ( new UserLoginFailureEvent ( context . UserName , " " , interactive : false ) ) ; } else if ( result . IsNotAllowed ) { _logger . LogInformation ( " " , context . UserName ) ; await _events . RaiseAsync ( new UserLoginFailureEvent ( context . UserName , " " , interactive : false ) ) ; } else { _logger . LogInformation ( " " , context . UserName ) ; await _events . RaiseAsync ( new UserLoginFailureEvent ( context . UserName , " " , interactive : false ) ) ; } } else { _logger . LogInformation ( " " , context . UserName ) ; await _events . RaiseAsync ( new UserLoginFailureEvent ( context . UserName , " " , interactive : false ) ) ; } context . Result = new GrantValidationResult ( TokenRequestErrors . InvalidGrant ) ; }
Validates the resource owner password credential
Validates the resource owner password credential
None
context
ResourceOwnerPasswordValidationContext
None