Skip to content
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

Enforce openid scope on the AuthenticationAPIClient #455

Merged
merged 2 commits into from
Feb 10, 2021
Merged

Conversation

lbalmaceda
Copy link
Contributor

Changes

The requests affected by this change include all /oauth/token calls but the one that is used to renew the credentials with a Refresh Token.

The logic is as follows:

  • Each of these requests will be set an initial default scope of "openid profile email" to match the WebAuthProvider default scope.
  • If a scope value is set by the developer, it will be checked that it includes "openid" and it will append "openid" if it's missing.

This change is to ensure the tokens response from the server is compliant with the OpenID Connect spec.

This is NOT a breaking change

@lbalmaceda lbalmaceda added CH: Changed medium Medium review labels Feb 9, 2021
@lbalmaceda lbalmaceda added this to the v2-Next milestone Feb 9, 2021
@lbalmaceda lbalmaceda requested a review from jimmyjames February 9, 2021 18:04
@lbalmaceda lbalmaceda requested a review from a team as a code owner February 9, 2021 18:04
val request = BaseAuthenticationRequest(factory.post(url.toString(), credentialsAdapter))
request.addParameters(parameters)
return request
return loginWithToken(parameters)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

most logic was already available on this method, so I simplified this call

@@ -64,7 +66,7 @@ public class ParameterBuilder private constructor(parameters: Map<String, String
* @return itself
*/
public fun setScope(scope: String): ParameterBuilder {
return set(SCOPE_KEY, scope)
return set(SCOPE_KEY, OidcUtils.includeRequiredScope(scope))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

when a scope is set through this setter, it will be checked so that it contains "openid"

*
* @return a new builder
*/
@JvmStatic
public fun newAuthenticationBuilder(): ParameterBuilder {
return newBuilder()
.setScope(SCOPE_OPENID)
.setScope(OidcUtils.DEFAULT_SCOPE)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this method will always add as default the scope of "openid profile email". It can be changed later by the dev.

@@ -55,7 +56,7 @@ internal class OAuthManager(
}

fun startAuthentication(context: Context, redirectUri: String, requestCode: Int) {
addRequiredScope(parameters)
OidcUtils.includeDefaultScope(parameters)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved the method to a different class, but it's the same logic (test remains unchanged)

} else {
value
}
return addParameter(name, anyValue)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

delegates to the Any method signature

@@ -1505,6 +1509,30 @@ public class AuthenticationAPIClientTest {
assertThat(body, Matchers.hasEntry("client_id", CLIENT_ID))
assertThat(body, Matchers.hasEntry("refresh_token", "refreshToken"))
assertThat(body, Matchers.hasEntry("grant_type", "refresh_token"))
assertThat(body, Matchers.not(Matchers.hasKey("scope")))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this ensures the renew auth method is not setting a scope value by default

}

@Test
public fun shouldRenewAuthWithOAuthTokenAndCustomScope() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this checks that it can still be set a scope by the dev later, if desired

@lbalmaceda lbalmaceda merged commit 4d00b5b into v2-dev Feb 10, 2021
@lbalmaceda lbalmaceda deleted the enforce-oidc branch February 10, 2021 09:48
@lbalmaceda lbalmaceda modified the milestones: v2-Next, 2.0.0 Feb 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants