Skip to content

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 IsSupportedByBrowser remains false.

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.browser is lower than 1.9.0, AuthTab is unavailable and LaunchAsync returns a failure result.
  • If androidx.browser is 1.9.0+ and the browser doesn't support AuthTab, AuthTab automatically falls back to a Custom Tab.
  • Use IsSupportedByBrowser to check if AuthTab is supported by the current browser if you need to manually decide fallback behavior.

Properties

IsSupportedByBrowser

public static bool IsSupportedByBrowser { get; }

Whether AuthTab is supported by the current browser version.

Returns

  • true if AuthTab is supported by the current browser; otherwise false.

Remarks

  • If androidx.browser is lower than 1.9.0, AuthTab is unavailable and this remains false.
  • If androidx.browser is 1.9.0 or 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 when url or redirectScheme is 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 when url or redirectHost is 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}");
        }
    }
}