Skip to content

Don't use oidc scopes_supported for scope as default in ClientRegistrations #8790

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

Closed
wants to merge 2 commits into from

Conversation

martin-v
Copy link
Contributor

@martin-v martin-v commented Jul 2, 2020

fixes #8514

@pivotal-issuemaster
Copy link

@martin-v Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 2, 2020
@pivotal-issuemaster
Copy link

@martin-v Thank you for signing the Contributor License Agreement!

Copy link
Contributor

@jgrandja jgrandja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @martin-v. Please see review comment.

@@ -268,16 +266,6 @@ private static ClientAuthenticationMethod getClientAuthenticationMethod(String i
+ "ClientAuthenticationMethod.NONE are supported. The issuer \"" + issuer + "\" returned a configuration of " + metadataAuthMethods);
}

private static List<String> getScopes(AuthorizationServerMetadata metadata) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of removing this method, let's apply this logic:

if metadata.getScopes() contains openid then
default to openid, profile, email
else
default to openid

This will ensure backwards compatibility when CommonOAuth2Provider.GOOGLE and CommonOAuth2Provider.OKTA is used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But for CommonOAuth2Provider the scopes are defined, and this is also tested in CommonOAuth2ProviderTests so these stick with openid, profile, email. You are probaply mislead by the bad test-data naming in ClientRegistrationsBeanDefinitionParserTests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jgrandja Did you get a chance to look at that remark?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@martin-v Apologies, my last comment was not that clear.

Let's assume the user has configured this:

spring:
  security:
    oauth2:
      client:
        registration:
          google:
            client-id: id
            client-secret: secret
        provider:
          google:
            issuer-uri: https://accounts.google.com

Google discovery endpoint returns openid, profile, email in the scopes_supported parameter, which initializes the ClientRegistration with the 3 scopes.

The changes in this PR would initialize the ClientRegistration with just the openid scope, which changes the runtime behaviour as the UserInfo endpoint would not be called by OidcUserService as it doesn't contain at least one of the accessible scopes.

The logic proposed in previous comment would preserve this behaviour. Furthermore, if the openid scope is returned in scopes_supported then we know the provider supports OpenID Connect and the UserInfo endpoint so it makes sense to also default to profile, email to enable the UserInfo endpoint call.

Makes sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

profile, email are optional scopes in openid-connect, see https://openid.net/specs/openid-connect-core-1_0.html#ScopeClaims

One option is if the profile, email is listed in scopes_supported then we add these, but this still can cause the problem from #8514 (If it is listed in 'scopes_supported', this does not mean that it is supported for that particular client)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jgrandja sry, didn't see it.

If we leave it empty we still have the problem mentioned in #8514 (comment) but we can't fix both issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I can do the change, if you still prefer the empty solution.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@martin-v Regarding...

If we leave it empty we still have the problem mentioned in #8514

I realize that openid is a required scope for OIDC. However, as I mentioned in my previous comment

We cannot assume that all ClientRegistation's are configured for oauth2Login(), therefore we should not default to openid or any of the additional OIDC scopes. There may be ClientRegistation's that are configured for OAuth 2.0 authorization_code or client_credentials and defaulting to openid would be invalid.

Please go ahead with the change on NOT assigning any defaults to ClientRegistration.scope(). This change will NOT be backported and will only go into the 5.4 release.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@martin-v 5.4.0 is being released Sep 2 and I need to get this change in. Are you able to update, as per my last comment, this week?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, didn't notice your response. I will update the PR in a few minutes.

@jgrandja jgrandja added in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 3, 2020
@jgrandja jgrandja added this to the 5.4.0-RC1 milestone Jul 3, 2020
@jgrandja jgrandja modified the milestones: 5.4.0-RC1, 5.4.0 Aug 5, 2020
@martin-v martin-v requested a review from jgrandja August 17, 2020 11:08
@jgrandja jgrandja added the status: duplicate A duplicate of another issue label Aug 20, 2020
@jgrandja
Copy link
Contributor

Thanks for the updates @martin-v ! This is now in master.

@jgrandja jgrandja closed this Aug 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) status: duplicate A duplicate of another issue type: bug A general bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

scopes_supported metadata should not be used as default in ClientRegistrations
4 participants