Some LLM providers use OAuth for authentication instead of API keys. Goose supports OAuth device code flow for secure, user-friendly authentication.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/block/goose/llms.txt
Use this file to discover all available pages before exploring further.
OAuth in Goose
Goose’s OAuth implementation (crates/goose/src/providers/oauth.rs) supports:
- Device Code Flow - User authenticates via browser
- Token Caching - Tokens stored securely, reused across sessions
- Automatic Refresh - Expired tokens refreshed automatically
- PKCE - Secure authorization without client secrets
When to Use OAuth
Use OAuth authentication when:- Provider requires OAuth (e.g., Databricks)
- You want SSO integration
- API keys aren’t available or practical
- Enterprise authentication is needed
OAuth Flow Overview
Implementing OAuth Providers
1. Define Provider with OAuth ConfigKey
In yourProviderDef implementation:
2. Implement configure_oauth Method
3. Use Token in Requests
OAuth Token Management
Token Storage
Tokens are stored in:- Host URL
- Client ID
- Requested scopes
Token Structure
Automatic Refresh
The OAuth module automatically:- Checks if cached token exists
- Validates expiration time
- Refreshes if expired using refresh token
- Falls back to full OAuth flow if refresh fails
Complete Example: Databricks Provider
Databricks uses OAuth for authentication:OAuth Configuration UI
When a user configures an OAuth provider:- Detects OAuth requirement from
ConfigKey::new_oauth() - Calls
provider.configure_oauth() - Opens browser for authentication
- Displays success message
- Caches tokens for future use
Testing OAuth Providers
Manual Testing
Integration Tests
Skip OAuth in tests by mocking:Security Considerations
PKCE (Proof Key for Code Exchange)
Goose uses PKCE for secure OAuth:Token Storage
Tokens are stored:- In user’s config directory
- With restrictive file permissions
- Hashed filename for privacy
- Never logged or printed
State Parameter
CSRF protection using state parameter:Advanced OAuth Features
Custom Scopes
Custom Client ID
Custom Redirect Port
Troubleshooting
Browser Doesn’t Open
If browser fails to open automatically:Token Refresh Fails
If refresh fails:- Falls back to full OAuth flow
- User re-authenticates in browser
- New tokens cached
Port Already in Use
If redirect port is occupied:- Use port 0 for auto-assignment
- Or specify different port
Token Expiration
Tokens automatically refresh before expiration:OAuth vs API Keys
Use OAuth when:- Provider requires it
- Enterprise SSO needed
- Temporary access desired
- Fine-grained permissions required
- Simpler for users
- Provider supports them
- No enterprise requirements
- Faster setup needed
Next Steps
- Implement Custom Providers
- Learn about Declarative Providers
- See OAuth implementation in
crates/goose/src/providers/oauth.rs