-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Userinfo endpoint with OAuth2 requires openid scope #918
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
@mpsanchis, thanks for your interest in the project!
You're correct that this is currently the behavior. The UserInfo endpoint has been implemented specific to OpenID Connect.
I believe it would always be recommended to use OIDC for authentication, as it was designed to address specific issues with using OAuth2 for authentication. Having said that, you're right that Spring Security includes support for it by utilizing the UserInfo endpoint as mandatory in the case of OAuth2 only.
Other than providing a custom |
I will proceed with OIDC in that case. Thank you very much for the quick response! 😄 --
|
@mpsanchis The UserInfo Endpoint is specified in OpenID Connect Core 1.0. There is no equivalent in standard OAuth 2 because OAuth 2 is not intended to be used for User Authentication. OpenID Connect 1.0 is built on top of OAuth 2 to address User Authentication. Please review the Authorization Code Flow Steps for details on how this flow works. I'm going to close this as the UserInfo Endpoint is specifically implemented for OpenID Connect and not meant to be used in standard OAuth 2 flows. |
Dear @jgrandja , I understand that userinfo endpoint is for OIDC, not OA2. However my client is built with Spring Security, with the basic I am confused with what you mentioned back then:
and what you are saying now:
My understanding is that without OIDC in the scopes, my client should not call this endpoint in the first place. I know this would be an isse for the |
I am confused with what you mentioned back then:
Please review the reference on DefaultOAuth2UserService:
The
This is required for standard OAuth 2.0 Provider’s because we need a way to obtain User Information in order to login the user during an NOTE: the |
Thank you again, Joe. I hope this discussion is helpful for future users of Spring Security. |
@sjohnr @jgrandja @mpsanchis May you shed me some light on how to call Should I call it
I read some excellent oidc primer here: https://developer.okta.com/blog/2017/07/25/oidc-primer-part-1 and tried OIDC Now I want to apply these in SAS, I strictly followed SAS getting started guide: https://docs.spring.io/spring-authorization-server/docs/current/reference/html/ public RegisteredClientRepository registeredClientRepository() {
RegisteredClient registeredClient = RegisteredClient.withId(UUID.randomUUID().toString())
.clientId("messaging-client")
.clientSecret("{noop}secret")
.clientAuthenticationMethod(ClientAuthenticationMethod.CLIENT_SECRET_BASIC)
.authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE)
.authorizationGrantType(AuthorizationGrantType.REFRESH_TOKEN)
.authorizationGrantType(AuthorizationGrantType.CLIENT_CREDENTIALS)
.redirectUri("http://127.0.0.1:8080/login/oauth2/code/messaging-client-oidc")
.redirectUri("http://127.0.0.1:8080/authorized")
.scope(OidcScopes.OPENID)
.scope("message.read")
.scope("message.write")
.clientSettings(ClientSettings.builder().requireAuthorizationConsent(true).build())
.build();
return new InMemoryRegisteredClientRepository(registeredClient);
} I noticed there are two redirect_uris configured here. I thought the first one must be used for OIDC(the name implies). And I tried different combinations. Each time I got some Thank you. The following are the script I tried. user: `user/password`
export client_id=messaging-client
export redirect_uri=http://svc.com:8080/login/oauth2/code/messaging-client-oidc
browser http://auth.com:9090/oauth2/authorize?response_type=code&client_id=$client_id&redirect_uri=$redirect_uri&scope=openid
export code=mo7DoeekfJvhn0D8FgwkA4F0ZZZCL3jUWdlH_WcL9H4efZT4Rdn3Us8wi5EqtDZgRzWxg7nSAb5V9PmhcMQiZw5QgSjdoSdeXnjN7uNBHwoNGjqPwku094WqG_4SlSZ8
export access_token=$(curl -s -umessaging-client:secret \
-d "grant_type=authorization_code&redirect_uri=$redirect_uri&code=$code" \
http://auth.com:9090/oauth2/token | jq --raw-output '.access_token')
curl -i -H "Authorization: Bearer $access_token" http://auth.com:9090/userinfo |
Ah, I just read the userinfo endpoint document. https://docs.spring.io/spring-authorization-server/docs/current/reference/html/guides/how-to-userinfo.html#enable-user-info, and all works now. Thank you! |
If OIDC is not enabled, do I need to provide my own |
I have read @jgrandja 's comment in this thread and understood that if OIDC is not used (plain OAuth2), then
/userinfo
will always be called.In the documentation I have read how to enable the
/userinfo
endpoint, by making the Auth Server (AS) also a Resource Server, and having a JwtDecoder bean.My issue is that Spring's AS is using the
OidcUserInfoAuthenticationProvider
to authenticate the request to/userinfo
, and therefore requiresopenid
to be a scope (otherwise throws an exception signalinginsufficient scope
). But this means that the token is used for OIDC, and I was working on a simple app that would use only OAuth2.By the threads that I have read, I assume that preventing the client from accessing
/userinfo
is not an option. Is there a way of configuring the AS in a way that it authorizes the call for non-OIDC scopes? I thought this would be available out-of-the-box, since OAuth2 should be a simpler protocol than OIDC.Thank you in advance, and sorry if the formatting is not right. This is my first time opening an issue on GitHub. Let me know if I should change something.
The text was updated successfully, but these errors were encountered: