-
Notifications
You must be signed in to change notification settings - Fork 6k
Optimize OIDC for JWT based token to avoid user-info service call #5659
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
Comments
The If you look at the logic in
Otherwise the Does this help? |
I am not sure why would there be any restriction wrt. scope Seems it is made mandatory for Sample project that I am working is gb-oauth2-springboot-talk/Step-04-CustomProviderLogin where by for demo purpose I am configuring custom OAuth provider My apologies but not sure how or when spring security uses OIDC vs plain OAuth for authentication. |
@gburboz With regard to your comment
OpenID Connect authentication is triggered when the If the I hope this explains things? I'm going to close this issue as this works as expected. |
@jgrandja , it does not work as expected by OIDC spec. Current spring-security design/implementation mandates invocation of user-info service by the client while no such restriction is imposed by spec. In certain scenarios like Google OIDC, same info is already available in |
This is not correct. Have you reviewed the logic in Given this Google client registration:
The UserInfo endpoint will not be called. And given this Google client registration:
The UserInfo endpoint will not be called because the If you are still having issues than please put together a sample that reproduces this and I'll take a look. |
I tried with Used below to configure Google provider without
Considering scope has
Following is part of exception stack trace with
|
@gburboz Based on the stacktrace, |
Thanks @jgrandja , you are right about scope and after making changes you recommended it worked. I used space delimiter as that is what is mentioned in spec and it kind of worked with OP as it got what it expected but caused issues with spring-oauth. May be we should update scope as list to eliminate the confusion and/or do not allow space char which is special for OAuth scope. This will help eliminate hard to detect bugs like this where by OAuth is used instead of OIDC even though scope |
@gburboz This is not an issue directly related to Spring Security. Spring Boot reads these properties via it's YAML reader. It's up to the user to ensure they have a properly configured/formatted yaml properties.
|
@jgrandja Is this still true with Spring Security in Spring Boot 2.1.6?
The reason I ask is that I'm having an issue getting all the user's attributes when my access token contains the following for scopes. "scp": [
"openid",
"profile"
], When I have the following, it works (but the access token also has most of the user's attributes in it): "scope": "openid jhipster email offline_access profile", I'm using OIDC discovery and just defining an |
@jgrandja I think I can answer my own question. The |
@mraible The logic you outlined for The UserInfo Endpoint is called only during an |
@jgrandja |
This is an old thread but as I had the same question, perhaps it can help someone else. As explained in this discussion, the solution is to have the user-info-uri property empty. Do not use spring.security.oauth2.provider.[provider].issuer-uri property as it will automatically retrieve all provider info including the user info uri. instead provide : |
How can my application but then get an access? I have Spring Cloud API Gateway setup as a oauth2 client. And I now understand, that it has to have openid scope so it can call the user-info endpoint. But I need to get access tokens, which I can then pass downstream to my resource server. The token provided from Microsoft will just be for user-info (graph) endpoint but not for my custom APIs |
@JangoCG Good morning. |
Hi, I hope this helps |
This way, I don't need to make a request to obtain the information, so token renewal no longer goes through Graph. spring:
security:
oauth2:
client:
provider:
azure:
authorization-uri: https://login.microsoftonline.com/${TENANT_ID}/oauth2/v2.0/authorize
token-uri: https://login.microsoftonline.com/${TENANT_ID}/oauth2/v2.0/token
jwk-set-uri: https://login.microsoftonline.com/${TENANT_ID}/discovery/v2.0/keys
registration:
azure:
client-id: ${CLIENT_ID}
client-secret: ${CLIENT_SECRET}
scope: ${CLIENT_SCOPE}
authorization-grant-type: authorization_code
redirect-uri: "{baseUrl}/login/oauth2/code/{registrationId}"
resourceserver:
jwt:
issuer-uri: https://login.microsoftonline.com/${TENANT_ID}/v2.0
jwk-set-uri: https://login.microsoftonline.com/${TENANT_ID}/discovery/v2.0/keys |
Summary
Open ID Connect Core 1.0 specification does not mandate invocation of UserInfo Endpoint and set of Standard Claims can be returned in either ID Token and/or Access Token as JWT
@jgrandja please review this issue which came out based off discussion with @jzheaux on issue #5629
Actual Behavior
Currently OAuth client provider
user-info-uri
config is mandatory and this HTTP call is always invoked even though in some cases we already have necessary info already available.Expected Behavior
When OAuth client provider
user-info-uri
is not provided andopenid
scope is mentioned (OP is OIDC), then get the claims from ID Token (which is always JWT) and additionally from Access Token if that is also a JWT.Alternatively have an additional config parameter to drive this behavior so that it can also be used with plain OAuth without OIDC as we already drive user identity with
user-name-attribute
and rest of the claims can just be considered additional info.e.g.: In case of Google Open ID Connect we can obtain user information from the Google's OIDC - ID token without having to invoke an additional UserInfo endpoint.
Version
Spring Security 5
The text was updated successfully, but these errors were encountered: