Beispiel #1
0
        /// <summary>
        /// Validates the resource owner password credential.
        /// </summary>
        /// <param name="context">The context</param>
        /// <returns>A task instance</returns>
        public Task ValidateAsync(ResourceOwnerPasswordValidationContext context)
        {
            var validationMonad = _userService
                                  .Validate(context.UserName, context.Password);

            var claimsMonad = validationMonad
                              .Bind(_userService.GetClaims);

            switch (claimsMonad)
            {
            case Success <IEnumerable <Claim>, Error> claims:
                var user = (validationMonad as Success <User, Error>) !.Value;
                context.Result = new GrantValidationResult(user.Id.ToString(),
                                                           OidcConstants.AuthenticationMethods.Password,
                                                           _clock.UtcNow.UtcDateTime,
                                                           claims: claims.Value);
                break;

            case Failure <IEnumerable <Claim>, Error> _:
                var error = UserErrors.UserPasswordDidNotMatch();
                context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, error.Message);
                break;

            default:
                break;
            }

            return(Task.CompletedTask);
        }