-
Notifications
You must be signed in to change notification settings - Fork 146
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package com.auth0.android.authentication | ||
|
||
import com.auth0.android.request.internal.OidcUtils | ||
|
||
/** | ||
* Builder for Auth0 Authentication API parameters | ||
* You can build your parameters like this | ||
|
@@ -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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" |
||
} | ||
|
||
/** | ||
|
@@ -166,15 +168,16 @@ public class ParameterBuilder private constructor(parameters: Map<String, String | |
public const val AUDIENCE_KEY: String = "audience" | ||
|
||
/** | ||
* Creates a new instance of the builder using default values for login request, e.g. 'openid' for scope. | ||
* Creates a new instance of the builder using default values for login request, e.g. 'openid profile email' for scope. | ||
* | ||
* @return a new builder | ||
*/ | ||
@JvmStatic | ||
public fun newAuthenticationBuilder(): ParameterBuilder { | ||
return newBuilder() | ||
.setScope(SCOPE_OPENID) | ||
.setScope(OidcUtils.DEFAULT_SCOPE) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} | ||
|
||
/** | ||
* Creates a new instance of the builder. | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ import com.auth0.android.authentication.AuthenticationAPIClient | |
import com.auth0.android.authentication.AuthenticationException | ||
import com.auth0.android.callback.Callback | ||
import com.auth0.android.request.internal.Jwt | ||
import com.auth0.android.request.internal.OidcUtils | ||
import com.auth0.android.result.Credentials | ||
import java.security.SecureRandom | ||
import java.util.* | ||
|
@@ -55,7 +56,7 @@ internal class OAuthManager( | |
} | ||
|
||
fun startAuthentication(context: Context, redirectUri: String, requestCode: Int) { | ||
addRequiredScope(parameters) | ||
OidcUtils.includeDefaultScope(parameters) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) |
||
addPKCEParameters(parameters, redirectUri, headers) | ||
addClientParameters(parameters, redirectUri) | ||
addValidationParameters(parameters) | ||
|
@@ -224,19 +225,6 @@ internal class OAuthManager( | |
return uri | ||
} | ||
|
||
private fun addRequiredScope(parameters: MutableMap<String, String>) { | ||
if (!parameters.containsKey(KEY_SCOPE)) { | ||
parameters[KEY_SCOPE] = DEFAULT_SCOPE | ||
return | ||
} | ||
val existingScopes = parameters[KEY_SCOPE]!!.split(" ") | ||
.map { it.toLowerCase(Locale.ROOT) } | ||
if (!existingScopes.contains(REQUIRED_SCOPE)) { | ||
val requiredScopes = (existingScopes + REQUIRED_SCOPE).joinToString(separator = " ") | ||
parameters[KEY_SCOPE] = requiredScopes | ||
} | ||
} | ||
|
||
private fun addPKCEParameters( | ||
parameters: MutableMap<String, String>, | ||
redirectUri: String, | ||
|
There was a problem hiding this comment.
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