Can no longer add access token information to request parameters when customizing IOpenIdConnectUserTokenEndpoint when refreshing the token #465
Replies: 3 comments 2 replies
-
|
@simona-aveva this seems similar to https://github.com/orgs/DuendeSoftware/discussions/463, can you have a look? If similar indeed, an additional extension point is on its way to support this scenario. |
Beta Was this translation helpful? Give feedback.
-
|
As mentioned previously, I added if (tokenForParameters.Token?.TokenForSpecifiedParameters?.AccessToken != null)
{
parameters.Context.Add("AccessToken", tokenForParameters.Token.TokenForSpecifiedParameters.AccessToken.ToString());
}at the end of my custom implementation of IUserTokenStore.GetTokenAsync and then extracted that in my custom var accessToken = parameters.Context["AccessToken"].FirstOrDefault();
if (accessToken != null)
{
request.Parameters.Add("id_token_hint", accessToken);
}and now I can refresh my token. |
Beta Was this translation helpful? Give feedback.
-
|
After chatting with @Erwinvandervalk on this. One general observation is that You also may want to look into public class MyTokenRequestCustomizer(IHttpContextAccessor context) : ITokenRequestCustomizer
{
public async Task<TokenRequestParameters> Customize(HttpRequestContext httpRequest, TokenRequestParameters baseParameters,
CancellationToken cancellationToken = default)
{
// you can add the id token as the id token hint to the token request as follows:
var idToken = await context.HttpContext!.GetTokenAsync("id_token");
baseParameters.Parameters.Add("id_token_hint", idToken ?? "");
// you can also get the access token here,
var accessToken = await context.HttpContext!.GetTokenAsync("access_token");
return baseParameters;
}
}Here's a branch with an example (in the 'web' sample): https://github.com/DuendeSoftware/foss/blob/ev/atm/use-id-token-hint/access-token-management/samples/Web/Startup.cs#L158 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Previsouly, the IUserTokenEndpointService interface (now renamed IOpenIdConnectUserTokenEndpoint in 4.x) RefreshAccessTokenAsync function accepted a UserToken, which allowed me to add AccessToken information to the request parameters before performing the refresh, e.g
The new interface only accepts the UserRefreshToken, and I cannot call GetUserAccessTokenAsync from RefreshAccessTokenAsync as this would result in recursion (the token needs refreshing!).
I believe I can customize the IUserTokenStore and add the AccessToken to the parameters which would then get passed to RefreshAccessTokenAsync but this seems a bit convoluted. Is there any other way of doing this? Any help would be much appreciated.
Beta Was this translation helpful? Give feedback.
All reactions