# AuthTabIntent

Artifact: [androidx.browser:browser](https://developer.android.com/jetpack/androidx/releases/browser) [View Source](https://cs.android.com/search?q=file:androidx/browser/auth/AuthTabIntent.java+class:androidx.browser.auth.AuthTabIntent) Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/browser#1.9.0)

*** ** * ** ***


```
public class AuthTabIntent
```

<br />

*** ** * ** ***

Class holding an `https://developer.android.com/reference/android/content/Intent.html` and other data necessary to start an Auth Tab Activity.

Create an instance of this class using the `https://developer.android.com/reference/androidx/browser/auth/AuthTabIntent.Builder` and then call `https://developer.android.com/reference/androidx/browser/auth/AuthTabIntent#launch(androidx.activity.result.ActivityResultLauncher<android.content.Intent>,android.net.Uri,java.lang.String)` to present the auth page to the user.

Upon completion of the auth flow, the webpage should redirect to a URL with the custom scheme or an HTTPS URL with the host and path provided to the `https://developer.android.com/reference/androidx/browser/auth/AuthTabIntent#launch(androidx.activity.result.ActivityResultLauncher<android.content.Intent>,android.net.Uri,java.lang.String)` method.

Before starting the auth flow, you should create an `https://developer.android.com/reference/androidx/activity/result/ActivityResultLauncher` using `https://developer.android.com/reference/androidx/browser/auth/AuthTabIntent#registerActivityResultLauncher(androidx.activity.result.ActivityResultCaller,androidx.activity.result.ActivityResultCallback<androidx.browser.auth.AuthTabIntent.AuthResult>)`. This launcher should be created unconditionally before every fragment or activity creation. The `https://developer.android.com/reference/androidx/activity/result/ActivityResultCallback` provided to the launcher will be called with the result of the authentication flow, indicating success or failure.

If using an HTTPS redirect URL, you need to establish that your app and the redirect URL are owned by the same organization using Digital Asset Links. If the verification fails, the Auth Tab will return an `https://developer.android.com/reference/androidx/browser/auth/AuthTabIntent.AuthResult` with the result code RESULT_VERIFICATION_FAILED.

Code sample:

```
// In your activity
private final ActivityResultLauncher<Intent> mLauncher =
            AuthTabIntent.registerActivityResultLauncher(this, this::handleAuthResult);

private void handleAuthResult(AuthTabIntent.AuthResult result) {
    // Check the result code
    boolean success = result.resultCode == AuthTabIntent.RESULT_OK;
    String message =
            getResources()
                    .getString(success ? R.string.auth_tab_success : R.string.auth_tab_failure);
    // Retrieve the result Uri
    message += " uri: " + result.resultUri;
    Toast.makeText(this, message, Toast.LENGTH_LONG).show();
}

...

private void launchAuthTab() {
    AuthTabIntent authTabIntent = new AuthTabIntent.Builder().build();
    authTabIntent.launch(mLauncher, Uri.parse("https://www.example.com/auth"), "myscheme");
}

...
```

Note: The constants below are public for the browser implementation's benefit. You are strongly encouraged to use `https://developer.android.com/reference/androidx/browser/auth/AuthTabIntent.Builder`.

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/browser/auth/AuthTabIntent.AuthResult` Class containing Auth Tab result data. |
| `public class https://developer.android.com/reference/androidx/browser/auth/AuthTabIntent.AuthenticateUserResultContract extends https://developer.android.com/reference/androidx/activity/result/contract/ActivityResultContract<https://developer.android.com/reference/android/content/Intent.html, https://developer.android.com/reference/androidx/browser/auth/AuthTabIntent.AuthResult>` An `https://developer.android.com/reference/androidx/activity/result/contract/ActivityResultContract` for launching an Auth Tab and receiving the result. |
| `public final class https://developer.android.com/reference/androidx/browser/auth/AuthTabIntent.Builder` Builder class for `https://developer.android.com/reference/androidx/browser/auth/AuthTabIntent` objects. |

| ### Constants |
|---|---|
| `static final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/browser/auth/AuthTabIntent#EXTRA_HTTPS_REDIRECT_HOST() = "androidx.browser.auth.extra.HTTPS_REDIRECT_HOST"` String extra that determines the host of the https redirect. |
| `static final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/browser/auth/AuthTabIntent#EXTRA_HTTPS_REDIRECT_PATH() = "androidx.browser.auth.extra.HTTPS_REDIRECT_PATH"` String extra that determines the path of the https redirect. |
| `static final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/browser/auth/AuthTabIntent#EXTRA_LAUNCH_AUTH_TAB() = "androidx.browser.auth.extra.LAUNCH_AUTH_TAB"` Boolean extra that triggers an Auth Tab launch. |
| `static final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/browser/auth/AuthTabIntent#EXTRA_REDIRECT_SCHEME() = "androidx.browser.auth.extra.REDIRECT_SCHEME"` String extra that determines the redirect scheme. |
| `static final int` | `https://developer.android.com/reference/androidx/browser/auth/AuthTabIntent#RESULT_CANCELED() = 0` Result code for when the Auth Tab is closed without the user completing the auth flow, e.g. the user clicked the close button. |
| `static final int` | `https://developer.android.com/reference/androidx/browser/auth/AuthTabIntent#RESULT_OK() = -1` Result code for when the Auth Tab is closed as a result of the expected redirect, implying the auth flow was completed. |
| `static final int` | `https://developer.android.com/reference/androidx/browser/auth/AuthTabIntent#RESULT_UNKNOWN_CODE() = -2` Result code for when the Auth Tab implementation returns an invalid or unknown result. |
| `static final int` | `https://developer.android.com/reference/androidx/browser/auth/AuthTabIntent#RESULT_VERIFICATION_FAILED() = 2` Result code for when the Auth Tab is closed because the verification of the ownership of the HTTPS redirect URL failed. |
| `static final int` | `https://developer.android.com/reference/androidx/browser/auth/AuthTabIntent#RESULT_VERIFICATION_TIMED_OUT() = 3` Result code for when the Auth Tab is closed because the verification of the ownership of the HTTPS redirect URL couldn't be completed in a reasonable amount of time. |

| ### Public fields |
|---|---|
| `final @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Intent.html` | `https://developer.android.com/reference/androidx/browser/auth/AuthTabIntent#intent()` An `https://developer.android.com/reference/android/content/Intent.html` used to start the Auth Tab Activity. |

| ### Public methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/graphics/Bitmap.html` | `https://developer.android.com/reference/androidx/browser/auth/AuthTabIntent#getCloseButtonIcon()()` Returns the close button icon `https://developer.android.com/reference/android/graphics/Bitmap.html`. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/browser/auth/AuthTabColorSchemeParams` | `https://developer.android.com/reference/androidx/browser/auth/AuthTabIntent#getColorSchemeParams(android.content.Intent,int)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Intent.html intent, @https://developer.android.com/reference/androidx/annotation/IntRange(from = 1, to = 2) int colorScheme )` Retrieves the instance of `https://developer.android.com/reference/androidx/browser/auth/AuthTabColorSchemeParams` from an `https://developer.android.com/reference/android/content/Intent.html` for a given color scheme. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/browser/auth/AuthTabSession.PendingSession` | `@https://developer.android.com/reference/androidx/browser/customtabs/ExperimentalPendingSession https://developer.android.com/reference/androidx/browser/auth/AuthTabIntent#getPendingSession()()` |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/browser/auth/AuthTabSession` | `https://developer.android.com/reference/androidx/browser/auth/AuthTabIntent#getSession()()` |
| `boolean` | `https://developer.android.com/reference/androidx/browser/auth/AuthTabIntent#isEphemeralBrowsingEnabled()()` Returns whether ephemeral browsing is enabled. |
| `void` | `https://developer.android.com/reference/androidx/browser/auth/AuthTabIntent#launch(androidx.activity.result.ActivityResultLauncher<android.content.Intent>,android.net.Uri,java.lang.String)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/activity/result/ActivityResultLauncher<https://developer.android.com/reference/android/content/Intent.html> launcher, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html url, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html redirectScheme )` Launches an Auth Tab Activity. |
| `void` | `https://developer.android.com/reference/androidx/browser/auth/AuthTabIntent#launch(androidx.activity.result.ActivityResultLauncher<android.content.Intent>,android.net.Uri,java.lang.String,java.lang.String)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/activity/result/ActivityResultLauncher<https://developer.android.com/reference/android/content/Intent.html> launcher, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html url, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html redirectHost, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html redirectPath )` Launches an Auth Tab Activity. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/activity/result/ActivityResultLauncher<https://developer.android.com/reference/android/content/Intent.html>` | `https://developer.android.com/reference/androidx/browser/auth/AuthTabIntent#registerActivityResultLauncher(androidx.activity.result.ActivityResultCaller,androidx.activity.result.ActivityResultCallback<androidx.browser.auth.AuthTabIntent.AuthResult>)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/activity/result/ActivityResultCaller caller, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/activity/result/ActivityResultCallback<https://developer.android.com/reference/androidx/browser/auth/AuthTabIntent.AuthResult> callback )` Registers a request to launch an Auth Tab and returns an `https://developer.android.com/reference/androidx/activity/result/ActivityResultLauncher` that can be used to launch it. |

## Constants

### EXTRA_HTTPS_REDIRECT_HOST

Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/browser#1.9.0)

```
public static final String EXTRA_HTTPS_REDIRECT_HOST = "androidx.browser.auth.extra.HTTPS_REDIRECT_HOST"
```

String extra that determines the host of the https redirect.

### EXTRA_HTTPS_REDIRECT_PATH

Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/browser#1.9.0)

```
public static final String EXTRA_HTTPS_REDIRECT_PATH = "androidx.browser.auth.extra.HTTPS_REDIRECT_PATH"
```

String extra that determines the path of the https redirect.

### EXTRA_LAUNCH_AUTH_TAB

Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/browser#1.9.0)

```
public static final String EXTRA_LAUNCH_AUTH_TAB = "androidx.browser.auth.extra.LAUNCH_AUTH_TAB"
```

Boolean extra that triggers an Auth Tab launch.

### EXTRA_REDIRECT_SCHEME

Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/browser#1.9.0)

```
public static final String EXTRA_REDIRECT_SCHEME = "androidx.browser.auth.extra.REDIRECT_SCHEME"
```

String extra that determines the redirect scheme.

### RESULT_CANCELED

Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/browser#1.9.0)

```
public static final int RESULT_CANCELED = 0
```

Result code for when the Auth Tab is closed without the user completing the auth flow, e.g. the user clicked the close button.

### RESULT_OK

Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/browser#1.9.0)

```
public static final int RESULT_OK = -1
```

Result code for when the Auth Tab is closed as a result of the expected redirect, implying the auth flow was completed.

### RESULT_UNKNOWN_CODE

Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/browser#1.9.0)

```
public static final int RESULT_UNKNOWN_CODE = -2
```

Result code for when the Auth Tab implementation returns an invalid or unknown result.

### RESULT_VERIFICATION_FAILED

Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/browser#1.9.0)

```
public static final int RESULT_VERIFICATION_FAILED = 2
```

Result code for when the Auth Tab is closed because the verification of the ownership of the HTTPS redirect URL failed.

### RESULT_VERIFICATION_TIMED_OUT

Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/browser#1.9.0)

```
public static final int RESULT_VERIFICATION_TIMED_OUT = 3
```

Result code for when the Auth Tab is closed because the verification of the ownership of the HTTPS redirect URL couldn't be completed in a reasonable amount of time.

## Public fields

### intent

Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/browser#1.9.0)

```
public final @NonNull Intent intent
```

An `https://developer.android.com/reference/android/content/Intent.html` used to start the Auth Tab Activity.

## Public methods

### getCloseButtonIcon

Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/browser#1.9.0)

```
public @Nullable Bitmap getCloseButtonIcon()
```

Returns the close button icon `https://developer.android.com/reference/android/graphics/Bitmap.html`.

### getColorSchemeParams

Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/browser#1.9.0)

```
public static @NonNull AuthTabColorSchemeParams getColorSchemeParams(
    @NonNull Intent intent,
    @IntRange(from = 1, to = 2) int colorScheme
)
```

Retrieves the instance of `https://developer.android.com/reference/androidx/browser/auth/AuthTabColorSchemeParams` from an `https://developer.android.com/reference/android/content/Intent.html` for a given color scheme.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Intent.html intent` | `https://developer.android.com/reference/android/content/Intent.html` to retrieve the color scheme params from. |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 1, to = 2) int colorScheme` | A constant representing a color scheme. Must not be COLOR_SCHEME_SYSTEM. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/browser/auth/AuthTabColorSchemeParams` | An instance of `https://developer.android.com/reference/androidx/browser/auth/AuthTabColorSchemeParams` with retrieved params. |

### getPendingSession

Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/browser#1.9.0)

```
@ExperimentalPendingSession
public @Nullable AuthTabSession.PendingSession getPendingSession()
```

### getSession

Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/browser#1.9.0)

```
public @Nullable AuthTabSession getSession()
```

### isEphemeralBrowsingEnabled

Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/browser#1.9.0)

```
public boolean isEphemeralBrowsingEnabled()
```

Returns whether ephemeral browsing is enabled.

### launch

Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/browser#1.9.0)

```
public void launch(
    @NonNull ActivityResultLauncher<Intent> launcher,
    @NonNull Uri url,
    @NonNull String redirectScheme
)
```

Launches an Auth Tab Activity. Must be used for flows that result in a redirect with a custom scheme.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/activity/result/ActivityResultLauncher<https://developer.android.com/reference/android/content/Intent.html> launcher` | The `https://developer.android.com/reference/androidx/activity/result/ActivityResultLauncher` used to launch the Auth Tab. Use `https://developer.android.com/reference/androidx/browser/auth/AuthTabIntent#registerActivityResultLauncher(androidx.activity.result.ActivityResultCaller,androidx.activity.result.ActivityResultCallback<androidx.browser.auth.AuthTabIntent.AuthResult>)` to create this. See the class documentation for more details. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html url` | The url to load in the Auth Tab. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html redirectScheme` | The scheme of the resulting redirect. |

### launch

Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/browser#1.9.0)

```
public void launch(
    @NonNull ActivityResultLauncher<Intent> launcher,
    @NonNull Uri url,
    @NonNull String redirectHost,
    @NonNull String redirectPath
)
```

Launches an Auth Tab Activity. Must be used for flows that result in a redirect with the HTTPS scheme.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/activity/result/ActivityResultLauncher<https://developer.android.com/reference/android/content/Intent.html> launcher` | The `https://developer.android.com/reference/androidx/activity/result/ActivityResultLauncher` used to launch the Auth Tab. Use `https://developer.android.com/reference/androidx/browser/auth/AuthTabIntent#registerActivityResultLauncher(androidx.activity.result.ActivityResultCaller,androidx.activity.result.ActivityResultCallback<androidx.browser.auth.AuthTabIntent.AuthResult>)` to create this. See the class documentation for more details. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html url` | The url to load in the Auth Tab. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html redirectHost` | The host portion of the resulting https redirect. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html redirectPath` | The path portion of the resulting https redirect. |

### registerActivityResultLauncher

Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/browser#1.9.0)

```
public static @NonNull ActivityResultLauncher<Intent> registerActivityResultLauncher(
    @NonNull ActivityResultCaller caller,
    @NonNull ActivityResultCallback<AuthTabIntent.AuthResult> callback
)
```

Registers a request to launch an Auth Tab and returns an `https://developer.android.com/reference/androidx/activity/result/ActivityResultLauncher` that can be used to launch it. Should be called unconditionally before the fragment or activity is created.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/activity/result/ActivityResultCaller caller` | An `https://developer.android.com/reference/androidx/activity/result/ActivityResultCaller`, e.g. a `https://developer.android.com/reference/androidx/activity/ComponentActivity` or a `https://developer.android.com/reference/androidx/fragment/app/Fragment`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/activity/result/ActivityResultCallback<https://developer.android.com/reference/androidx/browser/auth/AuthTabIntent.AuthResult> callback` | An `https://developer.android.com/reference/androidx/activity/result/ActivityResultCallback` to be called with the auth result. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/activity/result/ActivityResultLauncher<https://developer.android.com/reference/android/content/Intent.html>` | An `https://developer.android.com/reference/androidx/activity/result/ActivityResultLauncher` to be passed to `https://developer.android.com/reference/androidx/browser/auth/AuthTabIntent#launch(androidx.activity.result.ActivityResultLauncher<android.content.Intent>,android.net.Uri,java.lang.String)`. |