Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Tauri Plugin OAuth
A minimalistic Rust library and Tauri plugin for handling browser-based OAuth flows in desktop applications. This plugin spawns a temporary localhost server to capture OAuth redirects, solving the challenge of using OAuth with desktop apps.
Why This Plugin?
Many OAuth providers (like Google and GitHub) don't allow custom URI schemes ("deep links") as redirect URLs. This plugin provides a solution by:
- Spawning a temporary local server
- Capturing the OAuth redirect
- Passing the authorization data back to your app
Note: For an alternative approach using deep linking, see tauri-plugin-deep-link. The deep-link plugin can automatically start your app if there's no open instance.
Installation
# Cargo.toml
[]
= "2"
For Tauri projects using npm or yarn:
# or
Usage
Rust
use ;
use start;
async
TypeScript
import { start, cancel, onUrl, onInvalidUrl } from '@fabianlars/tauri-plugin-oauth';
async function startOAuthFlow() {
try {
const port = await start();
console.log(`OAuth server started on port ${port}`);
// Set up listeners for OAuth results
await onUrl((url) => {
console.log('Received OAuth URL:', url);
// Handle the OAuth redirect
});
// Initiate your OAuth flow here
// ...
} catch (error) {
console.error('Error starting OAuth server:', error);
}
}
// Don't forget to stop the server when you're done
async function stopOAuthServer() {
try {
await cancel(port);
console.log('OAuth server stopped');
} catch (error) {
console.error('Error stopping OAuth server:', error);
}
}
Configuration
You can configure the plugin behavior using the OauthConfig
struct:
use OauthConfig;
let config = OauthConfig ;
start_with_config
.await
.expect;
Security Considerations
- Always validate the received OAuth URL on your server-side before considering it authentic.
- Use HTTPS for your OAuth flow to prevent man-in-the-middle attacks.
- Implement proper token storage and refresh mechanisms in your application.
Contributing
Contributions are always welcome! Please feel free to submit a Pull Request.
License
This project is dual-licensed under either of the following licenses, at your option: