-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Description
Expected Behavior
The implementations of OAuth2UserService
support the application/jwt
content type when fetching the UserInfo resource.
Related Spec Info:
If the UserInfo Response is signed and/or encrypted, then the Claims are returned in a JWT and the content-type MUST be application/jwt.
OpenID Connect Core 1.0 - 5.3.2. Successful UserInfo Response
Current Behavior
The implementations of OAuth2UserService
are DefaultOAuth2UserService
and OidcUserService
. These implementations only support the application/json
content type when fetching the UserInfo resource. Resulting in 406 Not Acceptable
when the given identity provider only allows application/jwt
or this error when provided with a custom restOperations
which allows application/jwt
:
Lines 139 to 147 in eff4cdc
catch (UnknownContentTypeException ex) { | |
String errorMessage = "An error occurred while attempting to retrieve the UserInfo Resource from '" | |
+ userRequest.getClientRegistration().getProviderDetails().getUserInfoEndpoint().getUri() | |
+ "': response contains invalid content type '" + ex.getContentType().toString() + "'. " | |
+ "The UserInfo Response should return a JSON object (content type 'application/json') " | |
+ "that contains a collection of name and value pairs of the claims about the authenticated End-User. " | |
+ "Please ensure the UserInfo Uri in UserInfoEndpoint for Client Registration '" | |
+ userRequest.getClientRegistration().getRegistrationId() + "' conforms to the UserInfo Endpoint, " | |
+ "as defined in OpenID Connect 1.0: 'https://openid.net/specs/openid-connect-core-1_0.html#UserInfo'"; |
Context
The identity provider we have to use is build with "high security in mind" and forces the use of signed JWT.
More in depth information and a workaround I found while developing: https://stackoverflow.com/questions/59876435/spring-fails-for-userinfo-endpoint-returning-signed-jwt