OAuth Guide
Cocobase simplifies third-party authentication by handling the complex OAuth exchange and automatically creating or linking user accounts.Supported Providers
- Google: Recommended for all platforms.
- GitHub: Best for developer-focused applications.
- Apple: Required for iOS apps with third-party login.
Configuration
Before implementing OAuth, you must configure your providers in the Cocobase Dashboard:- Go to Settings > Authentication > OAuth.
- Enable your desired providers.
- Enter your Client ID and Client Secret (obtained from the provider’s developer console).
- Add the Cocobase redirect URI to your provider’s allowed list:
https://api.cocobase.buzz/auth/oauth/{provider}/callback
OAuth Flow
Cocobase uses a two-step flow to handle OAuth.1. Get Authorization URL
Direct your user to the provider’s login page.- Endpoint:
GET /auth-collections/oauth/{provider}?redirect_uri={your_callback_url}
2. Verify and Login
Once the user completes the login, the provider redirects them back to yourredirect_uri with an authorization code. Send this code to Cocobase to complete the login.
- Endpoint:
POST /auth-collections/verify-{provider}-login - Body:
Implementation Examples
Google OAuth (Web)
Apple OAuth (iOS)
When using Apple Sign In on iOS, you typically use the native SDK to get anidentityToken and then send it to Cocobase.
Security Features
- State Parameter: Cocobase can automatically handle the
stateparameter to prevent CSRF attacks. - PKCE Support: Recommended for mobile and single-page applications.
- Secure Callbacks: Only allow redirects to domains whitelisted in your dashboard.
- Account Linking: If a user logs in with an email that already exists via a different provider, Cocobase can automatically link the accounts (configurable in settings).
Troubleshooting
- Redirect URI Mismatch: Ensure the URI in your dashboard, provider console, and API request are IDENTICAL.
- Scope Issues: Check if you’ve requested the correct scopes (e.g.,
email,profile) in the provider console. - Token Expiry: Auth codes from providers usually expire within minutes. Process them immediately.
