IdentityServer4 icon indicating copy to clipboard operation
IdentityServer4 copied to clipboard

DelegationGrantValidator ValidateAsync not being called

Open steven-rothwell opened this issue 6 years ago • 1 comments

I'm following the documentation for extension grants (http://docs.identityserver.io/en/latest/topics/extension_grants.html). Like the example, I am using "delegation" as the grant type. I copied the DelegationGrantValidator and added it in the DI like so:

services.AddIdentityServer()
  ...
  .AddExtensionGrantValidator<DelegationGrantValidator>();

I have the client setup in the Identity server with:

"AllowedGrantTypes": [
    "delegation"
]

In the api that is called by Postman (in the future an application), I get the current bearer token and strip "Bearer " from it. (I've tried keeping it in and made no difference.)

const string bearer = "Bearer ";
string authorizationHeader = _httpContextAccessor.HttpContext.Request.Headers[HeaderNames.Authorization];

                if (authorizationHeader == null)
                    throw new Exception($"{HeaderNames.Authorization} header not found.");

                var token = authorizationHeader.Substring(authorizationHeader.IndexOf(bearer) + bearer.Length);

But, when I try to get the access token:

var tokenResponse = await _httpClient.RequestTokenAsync(new TokenRequest
{
    Address = discoveryDocument.TokenEndpoint,
    ClientId = _identityServerSettings.ClientId,
    ClientSecret = _identityServerSettings.ClientSecret,
    GrantType = "delegation",
    Parameters = new Dictionary<string, string>
    {
        { "scope", "api2" },
        { "token", token }
    }
});

The DelegationGrantValidator constructor gets called multiple times, but

public async Task ValidateAsync(ExtensionGrantValidationContext context) never does. If I inspect the tokenResponse, I see that it returns BadRequest invalid_grant.

I have this question on Stack Overflow as well: https://stackoverflow.com/questions/60422182/delegationgrantvalidator-validateasync-not-being-called

steven-rothwell avatar Feb 27 '20 14:02 steven-rothwell

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 Apr 02 '20 15:04 lock[bot]