-
-
Notifications
You must be signed in to change notification settings - Fork 540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scopes are not added to (client credentials) access token #1202
Comments
Hi, As specified, the ability to post questions on GitHub is reserved to sponsors as a way to thank them. Please consider sponsoring the project or post your question on StackOverflow, where it will be visible by the community. Thanks. |
Sponsored. What do you mean by this...("Scopes are automatically added by OpenIddict in all access tokens." https://gitter.im/openiddict/openiddict-core?at=5ff487b1acd1e516f8d54f0b) Under "/connect/token" Exchange web api method, I found the reason why no scopes (standard or custom scopes) are not added to access token, because there is no code that adds the scopes to the access token. Am I missing something here? I need to add all claims I need manually? (scopes, aud etc) |
Thanks for that! ❤️
All tokens are derived from a single Hope that's clearer. |
I opened openiddict/openiddict-documentation#28 to make sure I don't forget this point when I'll add the scopes/resources docs. |
Thanks, everything works now! by the way, principal.SetScopes(request.GetScopes()), this actually adds each scope as a new claim, is it suppose to do this? or is it suppose to add each scope via space separated value under a single oi_scp claim? |
That's the expected behavior (and pretty much the reason why OpenIddict uses its own private scopes claims: we don't have to split a unique scope value each time we want to work with them) |
I have similar problem. I wondering why disscution above talking about So I change code block to below: if (request.IsClientCredentialsGrantType())
{
var application = await _applicationManager.FindByClientIdAsync(request.ClientId ?? "")
?? throw new InvalidOperationException("The application cannot be found.");
var identity = new ClaimsIdentity(TokenValidationParameters.DefaultAuthenticationType,
Claims.Name, Claims.Role);
identity.AddClaim(Claims.Subject, await _applicationManager.GetClientIdAsync(application) ?? "",
Destinations.AccessToken, Destinations.IdentityToken);
identity.AddClaim(Claims.Name, await _applicationManager.GetDisplayNameAsync(application) ?? "",
Destinations.AccessToken, Destinations.IdentityToken);
//add below
foreach (var scope in request.GetScopes())
{
identity.AddClaim(Claims.Scope, scope, Destinations.AccessToken, Destinations.IdentityToken);
}
//add above
return SignIn(new ClaimsPrincipal(identity), OpenIddictServerAspNetCoreDefaults.AuthenticationScheme);
} And it seem to solve no scope claim in access token. |
Hello @kevinchalet, I faced the same issue as @drsmile1001 and solved it the same way. However, I simply do not understand why this works and it feels hacky. What I would expect is that: identity.SetScopes(request.GetScopes()); and foreach (var scope in request.GetScopes())
{
identity.AddClaim(Claims.Scope, scope);
} are doing the same thing, but evidently they don't. From the code, I can see that they use the type I sponsored and will gladly use one of my yearly support tickets to understand what's going on :) Also, great work on this library. I enjoy working with it much more than I did with IdentityServer. |
Hey @hypdeb,
Great, thanks for that! 😃
It's important to note that the standard To understand why I've opted for private/internal claims, a bit of history is needed:
Of course, I could have used the generic
As you figured out, OpenIddict expects that you use the private scopes to represent the granted scopes. If you use JWT access tokens (the default format), it will end up returning a standard Also, it's worth noting that the standard TL;DR: if you really wanted to use foreach (var scope in request.GetScopes())
{
identity.AddClaim(Claims.Private.Scope, scope);
} Not an easy topic, but I hope it made things (a bit) clearer 😄 |
Thank you for the answer. I won't pretend I understood all of it, but I now know what I have to do with more confidence. |
Openiddict.AspNetCore (3.0.0-beta6.20527.75)
How to reproduce issue
The text was updated successfully, but these errors were encountered: