Skip to content

Some OAuth providers do not comply with specs #5657

@gburboz

Description

@gburboz

Summary

Accommodate popular social platforms that do not comply with OAuth 2.0 specs so that Spring Security OAuth is still usable with those providers. There should be feature available for some of the checks to be explicitly be relaxed at provider configuration.

In below cases, ability to explicitly configure default value when missing can help resolve the issue if client development team chooses to do so.

Error with LinkedIn due to missing token_type field in token response

Caused by: com.nimbusds.oauth2.sdk.ParseException: Missing JSON object member with key "token_type"
	at com.nimbusds.oauth2.sdk.util.JSONObjectUtils.getGeneric(JSONObjectUtils.java:127)
	at com.nimbusds.oauth2.sdk.util.JSONObjectUtils.getString(JSONObjectUtils.java:263)
	at com.nimbusds.oauth2.sdk.token.BearerAccessToken.parse(BearerAccessToken.java:187)
	...
	at com.nimbusds.oauth2.sdk.TokenResponse.parse(TokenResponse.java:95)
	at org.springframework.security.oauth2.client.endpoint.NimbusAuthorizationCodeTokenResponseClient.getTokenResponse(NimbusAuthorizationCodeTokenResponseClient.java:101)
	...

Error with StackExchange/StackOverflow due to missing Content-Type header in token response

Caused by: com.nimbusds.oauth2.sdk.ParseException: The HTTP Content-Type header must be application/json; charset=UTF-8
	at com.nimbusds.oauth2.sdk.util.ContentTypeUtils.ensureContentType(ContentTypeUtils.java:52)
	...
	at com.nimbusds.oauth2.sdk.http.HTTPResponse.getContentAsJSONObject(HTTPResponse.java:369)
	at com.nimbusds.oauth2.sdk.AccessTokenResponse.parse(AccessTokenResponse.java:235)
	at com.nimbusds.oauth2.sdk.TokenResponse.parse(TokenResponse.java:95)
	at org.springframework.security.oauth2.client.endpoint.NimbusAuthorizationCodeTokenResponseClient.getTokenResponse(NimbusAuthorizationCodeTokenResponseClient.java:101)
	...

Actual Behavior

As per OAuth spec, current validations are being correctly performed, but that hinders our ability to connect with popular social platforms that do not comply.

Expected Behavior

There should be an explicit configuration option available to skip some of the validations to accommodate popular social platforms that do not comply. When option to skip is not set, it should provide error message of why there is non compliance with spec and how to manually override this compliance check using configuration

Version

Spring Security 5

Sample

Following popular social platforms do not comply with OAuth 2.0 and should be accommodate

  1. LinkedIn does not send REQUIRED token_type field in token response
  2. StackExchange/StackOverflow does not set content-type response header to "application/json" in token response

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: oauth2An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions