Tauri Plugin PLAUTH
A Tauri plugin for authentication (PLAUTH) that currently supports macOS and iOS platforms only. The plugin implements ASWebAuthenticationSession for secure web-based authentication flows.
Platform Support
| Platform | Status | Notes |
|---|---|---|
| macOS | ✅ Full | Web view integration |
| iOS | ❌ Full | ASWebAuthenticationSession |
| Android | ❌ Not supported | Not planned |
| Linux | ❌ Not supported | Not planned |
| Windows | ❌ Not supported | Not planned |
Features
- macOS: Full support with web view integration and ASWebAuthenticationSession
- iOS: Full support with ASWebAuthenticationSession and UIKit integration
- Android: Not currently supported
- Linux: Not currently supported
- Windows: Not currently supported
Installation
Rust Dependencies
Add the following to your Cargo.toml:
[]
= "1.0.0"
Or use the cargo add command:
JavaScript/TypeScript Dependencies
# or
Usage
Rust Setup
In your src-tauri/build.rs:
In your src-tauri/src/main.rs:
JavaScript/TypeScript Usage
import { authenticate } from "tauri-plugin-plauth-api";
// Basic authentication
try {
const result = await authenticate({
url: "https://example.com/auth",
callback_url_scheme: "myapp://callback",
});
console.log("Authentication successful:", result);
} catch (error) {
console.error("Authentication failed:", error);
}
API Reference
authenticate(request: AuthRequest): Promise<AuthResponse>
Initiates an authentication flow using ASWebAuthenticationSession (iOS) or web view (macOS).
Parameters
url(string): The authentication URL to navigate tocallback_url_scheme(string): The URL scheme to handle the callbackpresentation_context_provider(optional): Custom presentation context provider
Returns
AuthResponse: Object containing the authentication result
Examples
examples/tauri-app/- Example Tauri application demonstrating plugin usage on macOS with React frontend- iOS support is available through the same plugin interface with ASWebAuthenticationSession integration
Code Organization & Structure
Rust Code Structure
src/lib.rs- Main plugin entry point and exportssrc/commands.rs- Tauri command implementationssrc/models.rs- Data structures and typessrc/error.rs- Error handling and custom error typessrc/desktop.rs- macOS-specific implementationssrc/mobile.rs- iOS-specific implementations
Platform-Specific Code
ios/- iOS-specific Swift code with ASWebAuthenticationSessionmacos/- macOS-specific Swift code with ASWebAuthenticationSessionguest-js/- JavaScript/TypeScript client code- Note: Android support is not currently implemented
Known Issues
Authentication Dialog Shows "(null)" During Development
Issue: When running the application in development mode (cargo tauri dev), the authentication dialog may display "(null)" instead of the proper application name.
Cause: This is a known issue with Tauri development mode where the application metadata is not properly loaded.
Solutions:
1. Test with Built Bundle (Recommended)
Build and test the application as a bundle instead of development mode:
# Test the built .app bundle or .dmg file
2. Check Tauri Configuration
Ensure your tauri.conf.json has the correct productName:
3. Add/Update Info.plist
Create or update src-tauri/Info.plist with proper bundle information:
ITSAppUsesNonExemptEncryption
CFBundleVersion
1
CFBundleDisplayName
Your App Name
CFBundleName
Your App Name
Note: This issue only affects development mode and will not occur in production builds.
Development
Prerequisites
- Rust 1.77.2+
- Tauri 2.7.0+
- Xcode (for iOS and macOS development)
- macOS (for development and testing)
- iOS Simulator or device (for iOS testing)
Building
# Build Rust plugin
# Build JavaScript/TypeScript client
Testing
# Run Rust tests
# Run example app
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
If you encounter any issues or have questions, please:
- Check the examples for usage patterns
- Search existing issues
- Create a new issue with detailed information about your problem
Changelog
1.0.0
- Initial release
- macOS and iOS support
- ASWebAuthenticationSession integration
- Basic authentication flow