AndroidAuthSession¶
Launches a web authentication flow that returns to the app via a redirect URL.
Kodster.InAppWebBrowser.Android.AndroidAuthSession
Overview¶
AndroidAuthSession is a specialized in-app browser session 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 AndroidBrowser, AndroidAuthSession:
- 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
Availability and fallback:
- If
androidx.browseris lower than1.9.0,AndroidAuthSessionis unavailable andStartAsyncreturns a failure result. - If
androidx.browseris1.9.0+and the browser doesn't supportAuthTab, it automatically falls back to a regular in-app browser. - Use
IsSupportedByBrowserto check whether the current browser natively supportsAndroidAuthSessionif you need to manually decide fallback behavior.
Properties¶
IsSupportedByBrowser¶
Whether AndroidAuthSession is supported by the current browser version.
Returns
trueif supported by the current browser; otherwisefalse.
Remarks
- If
androidx.browseris lower than1.9.0, this remainsfalse. - If
androidx.browseris1.9.0or higher, this reflects browser support forAndroidAuthSession. - Not required to check before calling
StartAsync(). - Use this property to manually decide fallback behavior (for example, launch with
AndroidBrowser).
Methods¶
StartAsync¶
public static Task<AndroidAuthResult> StartAsync(
string url,
string redirectScheme,
AndroidAuthSessionOptions options = null
)
Starts an authentication session for flows that result in a redirect with a custom URL scheme. Returns a task that completes with the session result.
Parameters
url(string): The URL to load in the authentication session.redirectScheme(string): The scheme of the resulting redirect.options(AndroidAuthSessionOptions, optional): Optional appearance and behavior customization for the session.
Returns
- A task that resolves to the session result.
Throws
ArgumentException: Thrown whenurlis null, empty, whitespace, or not a valid absolute http/https URL.ArgumentNullException: Thrown whenredirectSchemeis null, empty, or whitespace.
StartAsync¶
public static Task<AndroidAuthResult> StartAsync(
string url,
string redirectHost,
string redirectPath,
AndroidAuthSessionOptions options = null
)
Starts an authentication session for flows that result in a redirect with the HTTPS scheme. Returns a task that completes with the session result.
Parameters
url(string): The URL to load in the authentication session.redirectHost(string): The host portion of the resulting https redirect.redirectPath(string): The path portion of the resulting https redirect.options(AndroidAuthSessionOptions, optional): Optional appearance and behavior customization for the session.
Returns
- A task that resolves to the session result.
Throws
ArgumentException: Thrown whenurlis null, empty, whitespace, or not a valid absolute http/https URL.ArgumentNullException: Thrown whenredirectHostis null, empty, or whitespace.
Example¶
#if UNITY_ANDROID
using Kodster.InAppWebBrowser.Android;
using UnityEngine;
using System.Threading.Tasks;
public sealed class LoginManager : MonoBehaviour
{
public async Task LoginWithGoogle()
{
var options = new AndroidAuthSessionOptionsBuilder()
.WithColorScheme(AndroidColorScheme.System)
.Build();
var result = await AndroidAuthSession.StartAsync(
"https://accounts.google.com/o/oauth2/v2/auth?...",
"com.example.game",
options
);
if (result.Code == AndroidAuthResultCode.Success)
{
Debug.Log("Authentication successful!");
}
else
{
Debug.Log($"Authentication failed: {result.Message}");
}
}
}
#endif