AuthTab¶
Static API optimized for authentication flows.
Overview¶
AuthTab is a specialized Custom Tab designed for OAuth and authentication workflows.
- Initialization is handled automatically during plugin startup.
- Cleanup is registered automatically on
Application.quitting. - On non-Android platforms, initialization is skipped and
IsSupportedByBrowserremainsfalse.
Compared to general-purpose CustomTab, AuthTab:
- Strips unnecessary features: Removes UI elements and features not needed for authentication.
- Enhances security: Receives authentication data via direct callbacks instead of intents, eliminating the attack surface and code complexity of intent-based approaches. This direct data transfer between the Android API and your app prevents potential interference.
Perfect for:
- OAuth 2.0 flows (Google, GitHub, Facebook, etc.)
- Account linking
- Any authorization flow with a redirect URI scheme
AuthTab availability and fallback:
- If
androidx.browseris lower than1.9.0, AuthTab is unavailable andLaunchAsyncreturns a failure result. - If
androidx.browseris1.9.0+and the browser doesn't support AuthTab, AuthTab automatically falls back to a Custom Tab. - Use
IsSupportedByBrowserto check if AuthTab is supported by the current browser if you need to manually decide fallback behavior.
Properties¶
IsSupportedByBrowser¶
Whether AuthTab is supported by the current browser version.
Returns
trueif AuthTab is supported by the current browser; otherwisefalse.
Remarks
- If
androidx.browseris lower than1.9.0, AuthTab is unavailable and this remainsfalse. - If
androidx.browseris1.9.0or higher, this reflects browser support for AuthTab. - Not required to check before calling
LaunchAsync(). - Use this property to manually decide fallback behavior (for example, launch with
CustomTab).
Methods¶
LaunchAsync¶
public static Task<AuthTabResult> LaunchAsync(
string url,
string redirectScheme,
AuthTabOptions options = null
)
Launches an authentication flow and waits for the redirect using a redirect URI scheme.
Parameters
url(string): The authentication URL to open.redirectScheme(string): The URI scheme the authentication provider will redirect to upon completion.options(AuthTabOptions, optional): Visual and behavioral configuration.
Returns
- A
Task<AuthTabResult>containing the result code and message.
Throws
ArgumentNullException: Thrown whenurlorredirectSchemeis null, empty, or whitespace.
LaunchAsync¶
public static Task<AuthTabResult> LaunchAsync(
string url,
string redirectHost,
string redirectPath,
AuthTabOptions options = null
)
Launches an authentication flow and waits for the redirect using host and path parameters.
Parameters
url(string): The authentication URL to open.redirectHost(string): The host portion of the redirect URI.redirectPath(string): The path portion of the redirect URI.options(AuthTabOptions, optional): Visual and behavioral configuration.
Returns
- A
Task<AuthTabResult>containing the result code and message.
Throws
ArgumentNullException: Thrown whenurlorredirectHostis null, empty, or whitespace.
Example¶
using DreamWeaveStudio.AndroidCustomTabs;
using UnityEngine;
using System.Threading.Tasks;
public sealed class LoginManager : MonoBehaviour
{
public async Task LoginWithGoogle()
{
var options = new AuthTabOptionsBuilder()
.WithColorScheme(ColorScheme.System)
.Build();
var result = await AuthTab.LaunchAsync(
"https://accounts.google.com/o/oauth2/v2/auth?...",
"com.example.game",
options
);
if (result.Code == AuthTabResultCode.Ok)
{
Debug.Log("Authentication successful!");
}
else
{
Debug.Log($"Authentication failed: {result.Message}");
}
}
}