| Crates.io | tauri-plugin-google-auth |
| lib.rs | tauri-plugin-google-auth |
| version | 0.3.3 |
| created_at | 2025-08-26 16:03:05.41259+00 |
| updated_at | 2025-09-15 13:56:39.327898+00 |
| description | A Tauri v2 plugin that enables Google OAuth authentication |
| homepage | |
| repository | https://github.com/Choochmeque/tauri-plugin-google-auth |
| max_upload_size | |
| id | 1811378 |
| size | 248,368 |
A Tauri v2 plugin for Google OAuth authentication, providing seamless Google Sign-In integration for mobile and desktop applications.
Add the plugin to your Cargo.toml:
[dependencies]
tauri-plugin-google-auth = "0.3"
Install the JavaScript API package:
npm install @choochmeque/tauri-plugin-google-auth-api
# or
yarn add @choochmeque/tauri-plugin-google-auth-api
# or
pnpm add @choochmeque/tauri-plugin-google-auth-api
In your Tauri app's src-tauri/src/lib.rs:
use tauri_plugin_google_auth;
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_google_auth::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
Add to your src-tauri/capabilities/default.json:
{
"permissions": [
"google-auth:default"
]
}
Configure Google Sign-In:
Info.plistRequired Info.plist entries:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>YOUR_REVERSED_CLIENT_ID</string>
</array>
</dict>
</array>
Configure Google Cloud Console:
See ANDROID_SETUP.md for complete setup instructions.
Configure Google Cloud Console:
http://localhost to authorized redirect URIsRequired fields for desktop:
clientId: Your Google OAuth client IDclientSecret: Your Google OAuth client secret (required for desktop)scopes: At least one scope is requiredThe desktop implementation uses a local redirect server that:
redirectUri)import { signIn, signOut, refreshToken } from '@choochmeque/tauri-plugin-google-auth-api';
// Sign in with Google
async function authenticateUser() {
try {
const response = await signIn({
clientId: 'YOUR_GOOGLE_CLIENT_ID',
clientSecret: 'YOUR_CLIENT_SECRET', // Required for desktop platforms
scopes: ['openid', 'email', 'profile'],
hostedDomain: 'example.com', // Optional: restrict to specific domain
loginHint: 'user@example.com', // Optional: pre-fill email
redirectUri: 'http://localhost:8080', // Optional: specify custom redirect URI
successHtmlResponse: '<h1>Success!</h1>' // Optional: custom success message (desktop)
})
console.log('ID Token:', response.idToken);
console.log('Access Token:', response.accessToken);
console.log('Refresh Token:', response.refreshToken);
console.log('Expires at:', new Date(response.expiresAt));
} catch (error) {
console.error('Authentication failed:', error);
}
}
// Sign out
async function logout(accessToken?: string) {
try {
// With token revocation (recommended)
await signOut({ accessToken });
// Or local sign-out only
// await signOut();
console.log('Successfully signed out');
} catch (error) {
console.error('Sign out failed:', error);
}
}
// Refresh tokens
async function refreshUserToken() {
try {
const response = await refreshToken();
console.log('New Access Token:', response.accessToken);
} catch (error) {
console.error('Token refresh failed:', error);
}
}
import { signIn } from '@choochmeque/tauri-plugin-google-auth-api';
const response = await signIn({
clientId: 'YOUR_CLIENT_ID',
clientSecret: 'YOUR_CLIENT_SECRET', // Optional: for certain OAuth flows
scopes: [
'openid',
'email',
'profile',
'https://www.googleapis.com/auth/drive.readonly'
],
hostedDomain: 'company.com', // Restrict to company domain
loginHint: 'john.doe@company.com', // Pre-fill the email field
redirectUri: 'custom://redirect' // Custom redirect URI
});
SignInOptionsinterface SignInOptions {
clientId: string; // Required: Google OAuth client ID
clientSecret?: string; // Required for desktop platforms
scopes?: string[]; // OAuth scopes to request (openid added automatically)
hostedDomain?: string; // Restrict authentication to a specific domain
loginHint?: string; // Email hint to pre-fill in the sign-in form
redirectUri?: string; // Custom redirect URI (desktop: defaults to random port)
successHtmlResponse?: string; // Custom HTML shown after auth (desktop only)
}
TokenResponseinterface TokenResponse {
idToken: string; // JWT ID token (UUID v7 placeholder on desktop currently)
accessToken: string; // OAuth access token for API calls
refreshToken?: string; // Refresh token (when offline access is granted)
expiresAt?: number; // Token expiration timestamp (seconds since epoch)
}
signIn(options: SignInOptions): Promise<TokenResponse>Initiates the Google Sign-In flow with the specified options.
signOut(options?: SignOutOptions): Promise<void>Signs out the current user. Can optionally revoke the access token with Google.
interface SignOutOptions {
accessToken?: string; // Token to revoke (if not provided, local sign-out only)
}
refreshToken(): Promise<TokenResponse>Refreshes the current access token using the stored refresh token.
The plugin provides detailed error information for common scenarios:
try {
await signIn({ clientId: 'YOUR_CLIENT_ID' });
} catch (error) {
switch (error.code) {
case 'USER_CANCELLED':
console.log('User cancelled the sign-in flow');
break;
case 'NETWORK_ERROR':
console.log('Network error occurred');
break;
case 'INVALID_CLIENT_ID':
console.log('Invalid client ID provided');
break;
case 'CONFIGURATION_ERROR':
console.log('Plugin not properly configured');
break;
default:
console.error('Unknown error:', error);
}
}
| Platform | Status | Implementation |
|---|---|---|
| iOS | ✅ Supported | Native Google Sign-In SDK via SimpleGoogleSignIn |
| Android | ✅ Supported | Credential Manager API |
| macOS | ✅ Supported | OAuth2 with local redirect server |
| Windows | ✅ Supported | OAuth2 with local redirect server |
| Linux | ✅ Supported | OAuth2 with local redirect server |
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)This project is licensed under the MIT License - see the LICENSE file for details.
If you encounter any issues or have questions, please file an issue on the GitHub repository.