Authentication
Authentication
Section titled “Authentication”Learn how to authenticate with the OpenSauce API.
Overview
Section titled “Overview”The OpenSauce API supports two authentication methods:
- API Keys - For programmatic access from your applications
- Session Cookies - For user authentication via GitHub OAuth
API Key Authentication
Section titled “API Key Authentication”Use API keys for server-to-server communication or client-side applications where you control the environment.
How to Use
Section titled “How to Use”Include your API key in the Authorization header:
const response = await fetch('https://api.os.eura.dev/api/v1/recipes', { headers: { 'Authorization': `Bearer YOUR_API_KEY` }});Creating API Keys
Section titled “Creating API Keys”- Go to the Dashboard
- Navigate to API Keys
- Click Create API Key
- Give it a descriptive name
- Copy the key (you won’t see it again!)
Best Practices
Section titled “Best Practices”- Never commit API keys to version control
- Use environment variables in production:
const apiKey = process.env.OPENSAUCE_API_KEY;
- Rotate keys regularly - Create new keys and revoke old ones
- Use different keys for different environments (development, staging, production)
Rate Limiting
Section titled “Rate Limiting”API key requests are rate limited to 100 requests per minute per key.
Session Authentication
Section titled “Session Authentication”Session authentication is used for user-specific actions like:
- Submitting recipes
- Managing your account
- Accessing your personal data
How It Works
Section titled “How It Works”-
Sign in via GitHub OAuth
- Visit dash.os.eura.dev/login
- Click “Sign in with GitHub”
- Authorize the application
- You’ll receive a session cookie
-
Use the session cookie
const response = await fetch('https://api.os.eura.dev/api/v1/recipes', {credentials: 'include' // This sends cookies});
Checking Your Session
Section titled “Checking Your Session”// Get current user infoconst response = await fetch('https://api.os.eura.dev/api/v1/auth/me', { credentials: 'include'});
const user = await response.json();// { id: 'usr_xxx', username: 'your-username', githubId: '12345' }Signing Out
Section titled “Signing Out”// Clear your sessionconst response = await fetch('https://api.os.eura.dev/api/v1/auth/logout', { method: 'POST', credentials: 'include'});GitHub OAuth Flow
Section titled “GitHub OAuth Flow”For custom integrations, you can implement the OAuth flow:
Step 1: Redirect to GitHub
Section titled “Step 1: Redirect to GitHub”const githubUrl = `https://api.os.eura.dev/api/v1/auth/github?redirect_uri=${encodeURIComponent('YOUR_CALLBACK_URL')}`;window.location.href = githubUrl;Step 2: Handle Callback
Section titled “Step 2: Handle Callback”After GitHub redirects back to your callback URL with a code parameter:
// The API handles the token exchange automatically// You'll receive a session cookie in the responseComparing Authentication Methods
Section titled “Comparing Authentication Methods”| Feature | API Key | Session Cookie |
|---|---|---|
| Best for | Application access | User actions |
| Required for | Public endpoints | Protected endpoints |
| Rate limited | Yes (100/min) | Yes (higher limit) |
| User context | No | Yes |
| Can submit recipes | No | Yes |
Protected Endpoints
Section titled “Protected Endpoints”The following endpoints require session authentication:
POST /api/v1/recipes- Submit a recipeGET /api/v1/auth/me- Get current userPOST /api/v1/auth/logout- Sign outPATCH /api/v1/admin/recipes/:id- Admin actions
Troubleshooting
Section titled “Troubleshooting”401 Unauthorized
Section titled “401 Unauthorized”This error means your authentication failed. Check:
- API Key: Is the key correct?
- Header: Are you using the
Bearerprefix? - Cookie: Are you including
credentials: 'include'? - Session: Has your session expired?
403 Forbidden
Section titled “403 Forbidden”This means you’re authenticated but don’t have permission. Check:
- Endpoint: Are you using the correct authentication method?
- Admin: Does this endpoint require admin access?
- Scope: Does your API key have the right permissions?
429 Too Many Requests
Section titled “429 Too Many Requests”You’ve hit the rate limit. Wait and try again, or consider:
- Caching: Cache responses locally
- Batching: Combine multiple requests
- Upgrade: Contact us for higher limits