Search code examples
c#identityserver4

IdentityServer4 unsupported_grant_type Error


I have been trying to get the simplest examples of IdentityServer4 to work for requesting access in pure code behind. I can get an access token when using a client request but not when doing a user login..

var discos = new DiscoveryClient(authority);
        var disco = await discos.GetAsync();

        if (disco.IsError)
        {
            Console.WriteLine(disco.Error);
            return null;
        }

        var tokenClient = new TokenClient(disco.TokenEndpoint, "ro.client", "secret");

        var tokenResponse = await tokenClient.RequestResourceOwnerPasswordAsync("username", "password", "api1");

This is the client making the request using user details. I get a perpetual unsupported_grant_type..

The server has it setup as:

 new Client
            {
                ClientId = "ro.client",
                AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,

                ClientSecrets =
                {
                    new Secret("secret".Sha256())
                },
                AllowedScopes = { "api1" }
            }

Can anyone please identify what Im mising. User can login using the front end quick start UI that the software offers and this is built in functionality.. Why wont it work if the company is valid.


Solution

  • Now resolved. I have managed to get this working using a newer version of the nuget package so may have been some conflict with what I was reading and old requirements.

    For ref I have uploaded the working demo with Server, API and console client to github: https://github.com/PheonixProject/IdentityServer4Demo