Skip to content

Commit

Permalink
Merge pull request #421 from auth0/rf-change-context
Browse files Browse the repository at this point in the history
Update WebAuthProvider#start required Context
  • Loading branch information
lbalmaceda authored Jan 8, 2021
2 parents 7564a5d + 0bfa7ba commit 13892fa
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.auth0.android.provider

import android.app.Activity
import android.content.Context
import android.net.Uri
import android.text.TextUtils
import android.util.Base64
Expand Down Expand Up @@ -57,13 +57,13 @@ internal class OAuthManager(
idTokenVerificationIssuer = if (TextUtils.isEmpty(issuer)) apiClient.baseURL else issuer
}

fun startAuthentication(activity: Activity?, redirectUri: String, requestCode: Int) {
fun startAuthentication(context: Context, redirectUri: String, requestCode: Int) {
addPKCEParameters(parameters, redirectUri, headers)
addClientParameters(parameters, redirectUri)
addValidationParameters(parameters)
val uri = buildAuthorizeUri()
this.requestCode = requestCode
AuthenticationActivity.authenticateUsingBrowser(activity!!, uri, ctOptions)
AuthenticationActivity.authenticateUsingBrowser(context, uri, ctOptions)
}

fun setHeaders(headers: Map<String, String>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/
package com.auth0.android.provider

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.util.Log
Expand Down Expand Up @@ -396,17 +395,17 @@ public object WebAuthProvider {
* device does not support the necessary algorithms to support Proof of Key Exchange (PKCE)
* (this is not expected).
*
* @param activity context to run the authentication
* @param context context to run the authentication
* @param callback to receive the parsed results
* @see AuthenticationException.isBrowserAppNotAvailable
* @see AuthenticationException.isPKCENotAvailable
*/
public fun start(
activity: Activity,
context: Context,
callback: Callback<Credentials, AuthenticationException>
) {
resetManagerInstance()
if (!ctOptions.hasCompatibleBrowser(activity.packageManager)) {
if (!ctOptions.hasCompatibleBrowser(context.packageManager)) {
val ex = AuthenticationException(
"a0.browser_not_available",
"No compatible Browser application is installed."
Expand All @@ -423,11 +422,11 @@ public object WebAuthProvider {
if (redirectUri == null) {
redirectUri = CallbackHelper.getCallbackUri(
scheme,
activity.applicationContext.packageName,
context.applicationContext.packageName,
account.getDomainUrl()
)
}
manager.startAuthentication(activity, redirectUri!!, 110)
manager.startAuthentication(context, redirectUri!!, 110)
}

private companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,17 @@
package com.auth0.android.provider;

import com.auth0.android.Auth0;
import com.auth0.android.authentication.AuthenticationException;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.function.ThrowingRunnable;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;


@RunWith(RobolectricTestRunner.class)
public class OAuthManagerTest {

@Mock
Auth0 account;
@Mock
AuthCallback callback;
@Mock
CustomTabsOptions ctOptions;

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
}

@Test
public void shouldHaveValidState() {
OAuthManager.assertValidState("1234567890", "1234567890");
Expand Down

0 comments on commit 13892fa

Please sign in to comment.