Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resource owner password credential grant type not supported

I'm using Identity Server 4 in my Angular 5 application.

I configured Identity Server in this way:

  public static IEnumerable<Client> GetClients()
        {
            return new List<Client>
            {
                new Client
                {
                    ClientId = "client",
                    AllowedGrantTypes = GrantTypes.ResourceOwnerPassword, 
                    AllowAccessTokensViaBrowser = true,
                    RequireClientSecret = false, 

                    AllowedScopes = {
                        "api1"
                    },

                    AllowedCorsOrigins = new List<string>
                    {
                        "http://localhost:4200"
                    } 
                }
            };
        }


    public void ConfigureServices(IServiceCollection services)
    {

        var cors = new DefaultCorsPolicyService(_loggerFactory.CreateLogger<DefaultCorsPolicyService>())
        {
            AllowedOrigins = { "http://localhost:4200" }
        };
        services.AddSingleton<ICorsPolicyService>(cors);

        services.AddIdentityServer()
                .AddDeveloperSigningCredential()
                .AddInMemoryApiResources(Config.GetApiResources())
                .AddInMemoryClients(Config.GetClients());
    }

And this is my Angular configuration:

export const oAuthDevelopmentConfig: AuthConfig = {

    clientId: "client",
    scope: "api1",
    oidc: false,
    issuer: "http://localhost:5000",
    requireHttps: false
}

and I use configuration this way:

...
    signin(): void {
        this.oAuthService
            .fetchTokenUsingPasswordFlowAndLoadUserProfile(this.model.username, this.model.password)
            .then(() => {
                this.authenticationService.init();
...

When I try to access to the server I receive the following error but I cannot understand where the problem is:

info: IdentityServer4.Hosting.IdentityServerMiddleware[0]
      Invoking IdentityServer endpoint: IdentityServer4.Endpoints.TokenEndpoint for /connect/token
info: IdentityServer4.Validation.NotSupportedResourceOwnerPasswordValidator[0]
      Resource owner password credential type not supported. Configure an IResourceOwnerPasswordValidator.
fail: IdentityServer4.Validation.TokenRequestValidator[0]
      Resource owner password credential grant type not supported
fail: IdentityServer4.Validation.TokenRequestValidator[0]
      {
        "ClientId": "client",
        "GrantType": "password",
        "Scopes": "api1",
        "UserName": "[email protected]",
        "Raw": {
          "grant_type": "password",
          "client_id": "client",
          "scope": "api1",
          "username": "[email protected]",
          "password": "***REDACTED***"
        }
      }

What I miss?

like image 454
danyolgiax Avatar asked Jan 29 '23 23:01

danyolgiax


1 Answers

This is an old question, but I did some head banging on the same problem today. I discoverd this method: AddResourceOwnerValidator. This method may not have existed when this question was asked.

Here is my AddIdentityServer configuration.

        services.AddIdentityServer(opt => opt.IssuerUri = issuerUri)
            .AddDeveloperSigningCredential()
            .AddInMemoryApiResources(IdServer.Configuration.GetApiResources())
            .AddInMemoryClients(IdServer.Configuration.GetClients())
            .AddProfileService<ProfileService>()
            .AddResourceOwnerValidator<ResourceOwnerPasswordValidator>()
            ;

At the time of the original question, the answer was probably like this, as shown in the question IdentityServer4 register UserService and get users from database in asp.net core

//Inject the classes we just created
services.AddTransient<IResourceOwnerPasswordValidator, ResourceOwnerPasswordValidator>();
services.AddTransient<IProfileService, ProfileService>();
like image 59
Phillip Scott Givens Avatar answered Jan 31 '23 12:01

Phillip Scott Givens