AuthTabIntent


@ExperimentalAuthTab
class AuthTabIntent


Class holding an Intent and other data necessary to start an Auth Tab Activity.

Create an instance of this class using the Builder and then call launch 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 launch method.

Before starting the auth flow, you should create an ActivityResultLauncher using registerActivityResultLauncher. This launcher should be created unconditionally before every fragment or activity creation. The 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 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 AuthTabIntent.Builder.

Summary

Nested types

Class containing Auth Tab result data.

Builder class for AuthTabIntent objects.

Constants

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

String extra that determines the host of the https redirect.

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

String extra that determines the path of the https redirect.

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

Boolean extra that triggers an Auth Tab launch.

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

String extra that determines the redirect scheme.

const 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.

const Int

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

const Int

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

const Int

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

const 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

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

Retrieves the instance of AuthTabColorSchemeParams from an Intent for a given color scheme.

AuthTabSession.PendingSession?
AuthTabSession?
Boolean

Returns whether ephemeral browsing is enabled.

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

Launches an Auth Tab Activity.

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

Launches an Auth Tab Activity.

java-static ActivityResultLauncher<Intent!>

Registers a request to launch an Auth Tab and returns an ActivityResultLauncher that can be used to launch it.

Public properties

Intent

An Intent used to start the Auth Tab Activity.

Constants

EXTRA_HTTPS_REDIRECT_HOST

Added in 1.9.0-alpha01
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-alpha01
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-alpha01
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-alpha01
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-alpha01
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-alpha01
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-alpha01
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-alpha01
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-alpha01
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

getColorSchemeParams

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

Retrieves the instance of AuthTabColorSchemeParams from an Intent for a given color scheme.

Parameters
intent: Intent

Intent to retrieve the color scheme params from.

colorScheme: @IntRange(from = 1, to = 2) Int

A constant representing a color scheme. Must not be COLOR_SCHEME_SYSTEM.

Returns
AuthTabColorSchemeParams

An instance of AuthTabColorSchemeParams with retrieved params.

getSession

Added in 1.9.0-alpha01
fun getSession(): AuthTabSession?

isEphemeralBrowsingEnabled

Added in 1.9.0-alpha01
@ExperimentalEphemeralBrowsing
fun isEphemeralBrowsingEnabled(): Boolean

Returns whether ephemeral browsing is enabled.

launch

Added in 1.9.0-alpha01
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: ActivityResultLauncher<Intent!>

The ActivityResultLauncher used to launch the Auth Tab. Use registerActivityResultLauncher to create this. See the class documentation for more details.

url: Uri

The url to load in the Auth Tab.

redirectScheme: String

The scheme of the resulting redirect.

launch

Added in 1.9.0-alpha01
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: ActivityResultLauncher<Intent!>

The ActivityResultLauncher used to launch the Auth Tab. Use registerActivityResultLauncher to create this. See the class documentation for more details.

url: Uri

The url to load in the Auth Tab.

redirectHost: String

The host portion of the resulting https redirect.

redirectPath: String

The path portion of the resulting https redirect.

registerActivityResultLauncher

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

Registers a request to launch an Auth Tab and returns an ActivityResultLauncher that can be used to launch it. Should be called unconditionally before the fragment or activity is created.

Returns
ActivityResultLauncher<Intent!>

An ActivityResultLauncher to be passed to launch.

Public properties

intent

Added in 1.9.0-alpha01
val intentIntent

An Intent used to start the Auth Tab Activity.