Skip to main content
Some LLM providers use OAuth for authentication instead of API keys. Goose supports OAuth device code flow for secure, user-friendly authentication.

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 your ProviderDef implementation:

2. Implement configure_oauth Method

3. Use Token in Requests

OAuth Token Management

Token Storage

Tokens are stored in:
The hash is based on:
  • Host URL
  • Client ID
  • Requested scopes
This ensures tokens are isolated per configuration.

Token Structure

Automatic Refresh

The OAuth module automatically:
  1. Checks if cached token exists
  2. Validates expiration time
  3. Refreshes if expired using refresh token
  4. 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:
Goose:
  1. Detects OAuth requirement from ConfigKey::new_oauth()
  2. Calls provider.configure_oauth()
  3. Opens browser for authentication
  4. Displays success message
  5. 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

Note: Port 0 allows OS to assign an available port.

Troubleshooting

Browser Doesn’t Open

If browser fails to open automatically:
User can copy/paste URL manually.

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
Use API Keys when:
  • Simpler for users
  • Provider supports them
  • No enterprise requirements
  • Faster setup needed

Next Steps