This package provides the TypeScript API for `tauri-plugin-auth-session`, a Tauri v2 plugin designed for secure in-app OAuth authentication across mobile and desktop platforms. It leverages native browser authentication sessions: `ASWebAuthenticationSession` on macOS and iOS, and Chrome Custom Tabs on Android. The plugin enables a seamless, secure authorization flow by capturing OAuth redirects to custom URL schemes directly within the app, bypassing the need for external browser launches or localhost web server listeners. It's crucial for Tauri v2 mobile development, where traditional desktop OAuth patterns are impractical. The current stable version is 0.2.2, indicating active development within the v0 series, with new features and stability improvements likely tied to the progression of Tauri v2 itself. Key differentiators include a single `start()` API call, native browser security (credentials never touch WebView), SSO support, and full compatibility with PKCE/OAuth 2.0/OIDC providers.
npm install tauri-plugin-auth-session-apiVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to initiate an OAuth 2.0 PKCE authorization flow using the `start` function, targeting a Google provider. It shows the construction of the authorization URL, handling the intercepted redirect callback, and extracting the authorization code and state.
Add `tauri-plugin-auth-session = { git = "https://github.com/yanqianglu/tauri-plugin-auth-session" }` to `src-tauri/Cargo.toml` and `tauri::Builder::default().plugin(tauri_plugin_auth_session::init()).run(...)` to your `lib.rs`.Add the provided `<activity>` and `<intent-filter>` XML snippet to `src-tauri/gen/android/app/src/main/AndroidManifest.xml`, replacing `myapp` with your actual custom URL scheme.
Add `"auth-session:default"` to the `permissions` array in your capability file, e.g., `src-tauri/capabilities/default.json`.
Handle the error gracefully in your application logic, or conditionally disable the authentication flow on unsupported platforms. Provide alternative authentication methods for Windows/Linux if necessary.
Install the correct version of the peer dependency: `npm install @tauri-apps/api@next` or `yarn add @tauri-apps/api@next`.
Verify the Rust installation steps, ensuring both `Cargo.toml` specifies the plugin dependency and `lib.rs` registers `tauri_plugin_auth_session::init()`.
Add `import { start } from 'tauri-plugin-auth-session-api';` at the top of your relevant source file.Add the provided `<activity>` and `<intent-filter>` XML snippet, replacing `myapp` with your actual scheme, to `src-tauri/gen/android/app/src/main/AndroidManifest.xml`.
Implement platform-specific logic (e.g., using `import { platform } from '@tauri-apps/api/os';`) to disable or provide alternative authentication methods when running on Windows or Linux, or ensure error handling is robust.Replace `const { start } = require('tauri-plugin-auth-session-api');` with `import { start } from 'tauri-plugin-auth-session-api';`.