AuthTabIntent
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 AuthTabIntent.AuthResult Class containing Auth Tab result data. |
class AuthTabIntent.Builder Builder class for |
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_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 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. |
const Int |
RESULT_UNKNOWN_CODE = -2 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 |
|
---|---|
Bitmap? |
Returns the close button icon |
java-static AuthTabColorSchemeParams |
getColorSchemeParams( Retrieves the instance of |
AuthTabSession.PendingSession? |
|
AuthTabSession? |
|
Boolean |
Returns whether ephemeral browsing is enabled. |
Unit |
launch( Launches an Auth Tab Activity. |
Unit |
launch( Launches an Auth Tab Activity. |
java-static ActivityResultLauncher<Intent!> |
registerActivityResultLauncher( Registers a request to launch an Auth Tab and returns an |
Constants
EXTRA_HTTPS_REDIRECT_HOST
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
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
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
const val EXTRA_REDIRECT_SCHEME = "androidx.browser.auth.extra.REDIRECT_SCHEME": String!
String extra that determines the redirect scheme.
RESULT_CANCELED
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
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
const val RESULT_UNKNOWN_CODE = -2: Int
Result code for when the Auth Tab implementation returns an invalid or unknown result.
RESULT_VERIFICATION_FAILED
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
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
fun getCloseButtonIcon(): Bitmap?
Returns the close button icon Bitmap
.
getColorSchemeParams
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 |
|
colorScheme: @IntRange(from = 1, to = 2) Int |
A constant representing a color scheme. Must not be COLOR_SCHEME_SYSTEM. |
Returns | |
---|---|
AuthTabColorSchemeParams |
An instance of |
getPendingSession
@ExperimentalPendingSession
fun getPendingSession(): AuthTabSession.PendingSession?
isEphemeralBrowsingEnabled
@ExperimentalEphemeralBrowsing
fun isEphemeralBrowsingEnabled(): Boolean
Returns whether ephemeral browsing is enabled.
launch
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 |
url: Uri |
The url to load in the Auth Tab. |
redirectScheme: String |
The scheme of the resulting redirect. |
launch
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 |
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
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.
Parameters | |
---|---|
caller: ActivityResultCaller |
An |
callback: ActivityResultCallback<AuthTabIntent.AuthResult!> |
An |
Returns | |
---|---|
ActivityResultLauncher<Intent!> |
An |