4

I was wondering if it is possible to implement with openiddict a delegation grant type similar to the one implemented here with Identity Server.

var result = await _validator.ValidateAccessTokenAsync(userToken);
if (result.IsError)
{
    context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant);
    return;
}

Is there any equivalent method to ValidateAccessTokenAsync in openiddict in order to validate the token and access some of its properties?

Pedro Faustino
  • 227
  • 3
  • 14

1 Answers1

5

Implementation of standard token exchange is tracked by https://github.com/openiddict/openiddict-core/issues/1249.

In the meantime, you can override the default ValidateTokenParameter handler to work with your custom grant and extract the access token from the customer parameter you use:

https://github.com/openiddict/openiddict-core/blob/422d8979adb8cdebc6c8c8e14faa1d736208271e/src/OpenIddict.Server/OpenIddictServerHandlers.cs#L168

Then, you can call the IOpenIddictServerDispatcher.DispatchAsync() method with an instance of ProcessAuthenticationContext to trigger an authentication event. If IsRejected is true, this means the token is not valid. Otherwise, you'll be able to access its claims principal.

Kévin Chalet
  • 39,509
  • 7
  • 121
  • 131