diff --git a/V2_MIGRATION_GUIDE.md b/V2_MIGRATION_GUIDE.md index f77704ca6..9f0361ec6 100644 --- a/V2_MIGRATION_GUIDE.md +++ b/V2_MIGRATION_GUIDE.md @@ -172,6 +172,10 @@ The ability to make requests to the [/delegation](https://auth0.com/docs/api/aut - `public void start(@NonNull Activity activity, @NonNull AuthCallback callback, int requestCode)`. Use `public void start(@NonNull Activity activity, @NonNull Callback callback)` instead. - `public Builder withResponseType(@ResponseType int type)`. There is no replacement; only Code + PKCE flow supported in v2. +#### WebAuthProvider.LogoutBuilder + +- `public void start(@NonNull Context context, @NonNull VoidCallback callback)`. Use `public void start(@NonNull Context context, @NonNull Callback callback)` instead. + #### UsersAPIClient - `public ParameterizableRequest, ManagementException> link(@NonNull String primaryUserId, @NonNull String secondaryToken)`. Use `public Request, ManagementException> link(@NonNull String primaryUserId, @NonNull String secondaryToken)` instead. diff --git a/auth0/src/main/java/com/auth0/android/authentication/AuthenticationException.kt b/auth0/src/main/java/com/auth0/android/authentication/AuthenticationException.kt index 6c915d158..e6aa6e906 100644 --- a/auth0/src/main/java/com/auth0/android/authentication/AuthenticationException.kt +++ b/auth0/src/main/java/com/auth0/android/authentication/AuthenticationException.kt @@ -195,7 +195,8 @@ public class AuthenticationException : Auth0Exception { public val isLoginRequired: Boolean get() = "login_required" == code - private companion object { + internal companion object { + internal const val ERROR_VALUE_AUTHENTICATION_CANCELED = "a0.authentication_canceled" private const val ERROR_KEY = "error" private const val CODE_KEY = "code" private const val DESCRIPTION_KEY = "description" diff --git a/auth0/src/main/java/com/auth0/android/provider/LogoutManager.kt b/auth0/src/main/java/com/auth0/android/provider/LogoutManager.kt index 691ac99e3..5e28616a1 100644 --- a/auth0/src/main/java/com/auth0/android/provider/LogoutManager.kt +++ b/auth0/src/main/java/com/auth0/android/provider/LogoutManager.kt @@ -4,12 +4,13 @@ import android.content.Context import android.net.Uri import android.util.Log import com.auth0.android.Auth0 -import com.auth0.android.Auth0Exception +import com.auth0.android.authentication.AuthenticationException +import com.auth0.android.callback.Callback import java.util.* internal class LogoutManager( private val account: Auth0, - private val callback: VoidCallback, + private val callback: Callback, returnToUrl: String, ctOptions: CustomTabsOptions ) : ResumableManager() { @@ -23,8 +24,10 @@ internal class LogoutManager( public override fun resume(result: AuthorizeResult): Boolean { if (result.isCanceled) { - val exception = - Auth0Exception("The user closed the browser app so the logout was cancelled.", null) + val exception = AuthenticationException( + AuthenticationException.ERROR_VALUE_AUTHENTICATION_CANCELED, + "The user closed the browser app so the logout was cancelled." + ) callback.onFailure(exception) } else { callback.onSuccess(null) diff --git a/auth0/src/main/java/com/auth0/android/provider/OAuthManager.kt b/auth0/src/main/java/com/auth0/android/provider/OAuthManager.kt index 35cc1cdd0..a12a46d8b 100644 --- a/auth0/src/main/java/com/auth0/android/provider/OAuthManager.kt +++ b/auth0/src/main/java/com/auth0/android/provider/OAuthManager.kt @@ -78,7 +78,7 @@ internal class OAuthManager( if (result.isCanceled) { //User cancelled the authentication val exception = AuthenticationException( - ERROR_VALUE_AUTHENTICATION_CANCELED, + AuthenticationException.ERROR_VALUE_AUTHENTICATION_CANCELED, "The user closed the browser app and the authentication was canceled." ) callback.onFailure(exception) @@ -265,7 +265,6 @@ internal class OAuthManager( const val KEY_CONNECTION = "connection" const val RESPONSE_TYPE_CODE = "code" private const val ERROR_VALUE_INVALID_CONFIGURATION = "a0.invalid_configuration" - private const val ERROR_VALUE_AUTHENTICATION_CANCELED = "a0.authentication_canceled" private const val ERROR_VALUE_ACCESS_DENIED = "access_denied" private const val ERROR_VALUE_UNAUTHORIZED = "unauthorized" private const val ERROR_VALUE_LOGIN_REQUIRED = "login_required" diff --git a/auth0/src/main/java/com/auth0/android/provider/WebAuthProvider.kt b/auth0/src/main/java/com/auth0/android/provider/WebAuthProvider.kt index bf8f860c0..6cf00cd57 100644 --- a/auth0/src/main/java/com/auth0/android/provider/WebAuthProvider.kt +++ b/auth0/src/main/java/com/auth0/android/provider/WebAuthProvider.kt @@ -152,13 +152,15 @@ public object WebAuthProvider { /** * Request the user session to be cleared. When successful, the callback will get invoked. - * An error is raised if there are no browser applications installed in the device. + * An error is raised if there are no browser applications installed in the device or if + * the user closed the browser before completing the logout. * * @param context to run the log out * @param callback to invoke when log out is successful * @see AuthenticationException.isBrowserAppNotAvailable + * @see AuthenticationException.isAuthenticationCanceled */ - public fun start(context: Context, callback: VoidCallback) { + public fun start(context: Context, callback: Callback) { resetManagerInstance() if (!ctOptions.hasCompatibleBrowser(context.packageManager)) { val ex = AuthenticationException( @@ -393,12 +395,13 @@ public object WebAuthProvider { * Request user Authentication. The result will be received in the callback. * An error is raised if there are no browser applications installed in the device, or if * device does not support the necessary algorithms to support Proof of Key Exchange (PKCE) - * (this is not expected). + * (this is not expected), or if the user closed the browser before completing the authentication. * * @param context context to run the authentication * @param callback to receive the parsed results * @see AuthenticationException.isBrowserAppNotAvailable * @see AuthenticationException.isPKCENotAvailable + * @see AuthenticationException.isAuthenticationCanceled */ public fun start( context: Context, diff --git a/auth0/src/test/java/com/auth0/android/provider/LogoutManagerTest.java b/auth0/src/test/java/com/auth0/android/provider/LogoutManagerTest.java index e3a8d0c05..7cf409d3d 100644 --- a/auth0/src/test/java/com/auth0/android/provider/LogoutManagerTest.java +++ b/auth0/src/test/java/com/auth0/android/provider/LogoutManagerTest.java @@ -1,7 +1,8 @@ package com.auth0.android.provider; import com.auth0.android.Auth0; -import com.auth0.android.Auth0Exception; +import com.auth0.android.authentication.AuthenticationException; +import com.auth0.android.callback.Callback; import org.junit.Before; import org.junit.Test; @@ -26,7 +27,7 @@ public class LogoutManagerTest { @Mock Auth0 account; @Mock - VoidCallback callback; + Callback callback; @Mock CustomTabsOptions customTabsOptions; @@ -41,10 +42,11 @@ public void shouldCallOnFailureWhenResumedWithCanceledResult() { AuthorizeResult result = mock(AuthorizeResult.class); when(result.isCanceled()).thenReturn(true); manager.resume(result); - ArgumentCaptor exceptionCaptor = ArgumentCaptor.forClass(Auth0Exception.class); + ArgumentCaptor exceptionCaptor = ArgumentCaptor.forClass(AuthenticationException.class); verify(callback).onFailure(exceptionCaptor.capture()); assertThat(exceptionCaptor.getValue(), is(notNullValue())); - assertThat(exceptionCaptor.getValue().getMessage(), is("The user closed the browser app so the logout was cancelled.")); + assertThat(exceptionCaptor.getValue().getCode(), is("a0.authentication_canceled")); + assertThat(exceptionCaptor.getValue().getDescription(), is("The user closed the browser app so the logout was cancelled.")); } @Test diff --git a/auth0/src/test/java/com/auth0/android/provider/WebAuthProviderTest.kt b/auth0/src/test/java/com/auth0/android/provider/WebAuthProviderTest.kt index 2d7a76bcd..a67501167 100644 --- a/auth0/src/test/java/com/auth0/android/provider/WebAuthProviderTest.kt +++ b/auth0/src/test/java/com/auth0/android/provider/WebAuthProviderTest.kt @@ -8,7 +8,6 @@ import android.os.Parcelable import androidx.test.espresso.intent.matcher.IntentMatchers import androidx.test.espresso.intent.matcher.UriMatchers import com.auth0.android.Auth0 -import com.auth0.android.Auth0Exception import com.auth0.android.MockAuth0 import com.auth0.android.authentication.AuthenticationException import com.auth0.android.callback.Callback @@ -60,11 +59,10 @@ public class WebAuthProviderTest { private lateinit var callback: Callback @Mock - private lateinit var voidCallback: VoidCallback + private lateinit var voidCallback: Callback private lateinit var activity: Activity private lateinit var account: Auth0 - private val auth0ExceptionCaptor: KArgumentCaptor = argumentCaptor() private val authExceptionCaptor: KArgumentCaptor = argumentCaptor() private val intentCaptor: KArgumentCaptor = argumentCaptor() private val credentialsCaptor: KArgumentCaptor = argumentCaptor() @@ -2326,13 +2324,13 @@ public class WebAuthProviderTest { //null data translates to result canceled val intent = createAuthIntent(null) Assert.assertTrue(resume(intent)) - verify(voidCallback).onFailure(auth0ExceptionCaptor.capture()) + verify(voidCallback).onFailure(authExceptionCaptor.capture()) MatcherAssert.assertThat( - auth0ExceptionCaptor.firstValue, + authExceptionCaptor.firstValue, `is`(notNullValue()) ) MatcherAssert.assertThat( - auth0ExceptionCaptor.firstValue.message, + authExceptionCaptor.firstValue.getDescription(), `is`("The user closed the browser app so the logout was cancelled.") ) assertThat(