# 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)

*** ** * ** ***


```
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/kotlin/androidx/browser/auth/AuthTabIntent.Builder` and then call `https://developer.android.com/reference/kotlin/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/kotlin/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/kotlin/androidx/activity/result/ActivityResultLauncher` using `https://developer.android.com/reference/kotlin/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/kotlin/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/kotlin/androidx/browser/auth/AuthTabIntent.AuthResult` with the result code RESULT_VERIFICATION_FAILED.

Code sample:

```kotlin
// 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/kotlin/androidx/browser/auth/AuthTabIntent.Builder`.

## Summary

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

| ### Constants |
|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | `https://developer.android.com/reference/kotlin/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. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | `https://developer.android.com/reference/kotlin/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. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | `https://developer.android.com/reference/kotlin/androidx/browser/auth/AuthTabIntent#EXTRA_LAUNCH_AUTH_TAB() = "androidx.browser.auth.extra.LAUNCH_AUTH_TAB"` Boolean extra that triggers an Auth Tab launch. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | `https://developer.android.com/reference/kotlin/androidx/browser/auth/AuthTabIntent#EXTRA_REDIRECT_SCHEME() = "androidx.browser.auth.extra.REDIRECT_SCHEME"` String extra that determines the redirect scheme. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/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. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/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. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/browser/auth/AuthTabIntent#RESULT_UNKNOWN_CODE() = -2` Result code for when the Auth Tab implementation returns an invalid or unknown result. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/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. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/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 functions |
|---|---|
| `https://developer.android.com/reference/android/graphics/Bitmap.html?` | `https://developer.android.com/reference/kotlin/androidx/browser/auth/AuthTabIntent#getCloseButtonIcon()()` Returns the close button icon `https://developer.android.com/reference/android/graphics/Bitmap.html`. |
| `java-static https://developer.android.com/reference/kotlin/androidx/browser/auth/AuthTabColorSchemeParams` | `https://developer.android.com/reference/kotlin/androidx/browser/auth/AuthTabIntent#getColorSchemeParams(android.content.Intent,int)( intent: https://developer.android.com/reference/android/content/Intent.html, colorScheme: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 1, to = 2) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Retrieves the instance of `https://developer.android.com/reference/kotlin/androidx/browser/auth/AuthTabColorSchemeParams` from an `https://developer.android.com/reference/android/content/Intent.html` for a given color scheme. |
| `https://developer.android.com/reference/kotlin/androidx/browser/auth/AuthTabSession.PendingSession?` | `@https://developer.android.com/reference/kotlin/androidx/browser/customtabs/ExperimentalPendingSession https://developer.android.com/reference/kotlin/androidx/browser/auth/AuthTabIntent#getPendingSession()()` |
| `https://developer.android.com/reference/kotlin/androidx/browser/auth/AuthTabSession?` | `https://developer.android.com/reference/kotlin/androidx/browser/auth/AuthTabIntent#getSession()()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/browser/auth/AuthTabIntent#isEphemeralBrowsingEnabled()()` Returns whether ephemeral browsing is enabled. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/browser/auth/AuthTabIntent#launch(androidx.activity.result.ActivityResultLauncher<android.content.Intent>,android.net.Uri,java.lang.String)( launcher: https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultLauncher<https://developer.android.com/reference/android/content/Intent.html!>, url: https://developer.android.com/reference/android/net/Uri.html, redirectScheme: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html )` Launches an Auth Tab Activity. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/browser/auth/AuthTabIntent#launch(androidx.activity.result.ActivityResultLauncher<android.content.Intent>,android.net.Uri,java.lang.String,java.lang.String)( launcher: https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultLauncher<https://developer.android.com/reference/android/content/Intent.html!>, url: https://developer.android.com/reference/android/net/Uri.html, redirectHost: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, redirectPath: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html )` Launches an Auth Tab Activity. |
| `java-static https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultLauncher<https://developer.android.com/reference/android/content/Intent.html!>` | `https://developer.android.com/reference/kotlin/androidx/browser/auth/AuthTabIntent#registerActivityResultLauncher(androidx.activity.result.ActivityResultCaller,androidx.activity.result.ActivityResultCallback<androidx.browser.auth.AuthTabIntent.AuthResult>)( caller: https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultCaller, callback: https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultCallback<https://developer.android.com/reference/kotlin/androidx/browser/auth/AuthTabIntent.AuthResult!> )` Registers a request to launch an Auth Tab and returns an `https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultLauncher` that can be used to launch it. |

| ### Public properties |
|---|---|
| `https://developer.android.com/reference/android/content/Intent.html` | `https://developer.android.com/reference/kotlin/androidx/browser/auth/AuthTabIntent#intent()` An `https://developer.android.com/reference/android/content/Intent.html` used to start the Auth Tab Activity. |

## Constants

### EXTRA_HTTPS_REDIRECT_HOST

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

```
const val EXTRA_HTTPS_REDIRECT_HOST = "androidx.browser.auth.extra.HTTPS_REDIRECT_HOST": String!
```

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)

```
const val EXTRA_HTTPS_REDIRECT_PATH = "androidx.browser.auth.extra.HTTPS_REDIRECT_PATH": String!
```

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)

```
const val EXTRA_LAUNCH_AUTH_TAB = "androidx.browser.auth.extra.LAUNCH_AUTH_TAB": String!
```

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)

```
const val EXTRA_REDIRECT_SCHEME = "androidx.browser.auth.extra.REDIRECT_SCHEME": String!
```

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)

```
const val RESULT_CANCELED = 0: Int
```

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)

```
const val RESULT_OK = -1: Int
```

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)

```
const val RESULT_UNKNOWN_CODE = -2: Int
```

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)

```
const val RESULT_VERIFICATION_FAILED = 2: Int
```

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)

```
const val RESULT_VERIFICATION_TIMED_OUT = 3: Int
```

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 functions

### getCloseButtonIcon

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

```
fun getCloseButtonIcon(): Bitmap?
```

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)

```
java-static fun getColorSchemeParams(
    intent: Intent,
    colorScheme: @IntRange(from = 1, to = 2) Int
): AuthTabColorSchemeParams
```

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

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

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/browser/auth/AuthTabColorSchemeParams` | An instance of `https://developer.android.com/reference/kotlin/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
fun getPendingSession(): AuthTabSession.PendingSession?
```

### getSession

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

```
fun getSession(): AuthTabSession?
```

### isEphemeralBrowsingEnabled

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

```
fun isEphemeralBrowsingEnabled(): Boolean
```

Returns whether ephemeral browsing is enabled.

### launch

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

```
fun launch(
    launcher: ActivityResultLauncher<Intent!>,
    url: Uri,
    redirectScheme: String
): Unit
```

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

| Parameters |
|---|---|
| `launcher: https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultLauncher<https://developer.android.com/reference/android/content/Intent.html!>` | The `https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultLauncher` used to launch the Auth Tab. Use `https://developer.android.com/reference/kotlin/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. |
| `url: https://developer.android.com/reference/android/net/Uri.html` | The url to load in the Auth Tab. |
| `redirectScheme: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The scheme of the resulting redirect. |

### launch

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

```
fun launch(
    launcher: ActivityResultLauncher<Intent!>,
    url: Uri,
    redirectHost: String,
    redirectPath: String
): Unit
```

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

| Parameters |
|---|---|
| `launcher: https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultLauncher<https://developer.android.com/reference/android/content/Intent.html!>` | The `https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultLauncher` used to launch the Auth Tab. Use `https://developer.android.com/reference/kotlin/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. |
| `url: https://developer.android.com/reference/android/net/Uri.html` | The url to load in the Auth Tab. |
| `redirectHost: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The host portion of the resulting https redirect. |
| `redirectPath: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | 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)

```
java-static fun registerActivityResultLauncher(
    caller: ActivityResultCaller,
    callback: ActivityResultCallback<AuthTabIntent.AuthResult!>
): ActivityResultLauncher<Intent!>
```

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

| Parameters |
|---|---|
| `caller: https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultCaller` | An `https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultCaller`, e.g. a `https://developer.android.com/reference/kotlin/androidx/activity/ComponentActivity` or a `https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment`. |
| `callback: https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultCallback<https://developer.android.com/reference/kotlin/androidx/browser/auth/AuthTabIntent.AuthResult!>` | An `https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultCallback` to be called with the auth result. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultLauncher<https://developer.android.com/reference/android/content/Intent.html!>` | An `https://developer.android.com/reference/kotlin/androidx/activity/result/ActivityResultLauncher` to be passed to `https://developer.android.com/reference/kotlin/androidx/browser/auth/AuthTabIntent#launch(androidx.activity.result.ActivityResultLauncher<android.content.Intent>,android.net.Uri,java.lang.String)`. |

## Public properties

### intent

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

```
val intent: Intent
```

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