IdentityServer4 icon indicating copy to clipboard operation
IdentityServer4 copied to clipboard

Internal server error on ResourceOwner Password Validation

Open testaco23 opened this issue 9 years ago • 3 comments

Hello, I'm trying to implement a ResourceOwnerPasswordValidator to retrieve my users from a database. It seems to be working whenever I use the login form from Identity Server, but not when using actual Resource Owner flow through a POST request.

Here's the code for ResourceOwnerPasswordValidator:

public class ResourceOwnerPasswordValidator : IResourceOwnerPasswordValidator
    {
        private static readonly UnitOfWork _unitOfWork = new UnitOfWork();

        public ResourceOwnerPasswordValidator()
        {
            //_myUserManager = new MyUserManager();
        }

        public async Task ValidateAsync(ResourceOwnerPasswordValidationContext context)
        {
            var usersList = GetUsers();

            var user = usersList.Where(u => u.Username == context.UserName).FirstOrDefault();
            if (user != null && user.Password == context.Password)
            {
                context.Result = new GrantValidationResult(
                    subject: user.Subject,
                    authenticationMethod: "custom",
                    claims: user.Claims);

                return;
            }
            context.Result = new GrantValidationResult(
                        TokenRequestErrors.InvalidGrant,
                        "invalid custom credential");
        }
}

I put a breakpoint in the Login action, but it never gets hit when using a POST request. On the return; line, it seems that the context result is correct, but it return a 500 response when sent.

testaco23 avatar Dec 20 '16 15:12 testaco23

..and you have registered the validator and use the token endpoint? logs?

leastprivilege avatar Dec 20 '16 16:12 leastprivilege

Nevermind, turns out it was an issue with conflicting Subjects on my user store, since I don't have a singe Users table.

testaco23 avatar Dec 20 '16 16:12 testaco23

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Jan 15 '20 07:01 lock[bot]