Authentication Methods
Midday supports three authentication methods:- API Keys - For server-to-server integrations
- OAuth 2.0 - For third-party applications
- Supabase JWT - For authenticated user sessions
Authorization header with a Bearer token:
API Keys
API keys are the recommended method for server-to-server integrations. They provide scoped access to your team’s data.Creating an API Key
API keys can be created through the Midday dashboard or programmatically using the tRPC API:API Key Format
API keys follow this format:mid_a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z6a7b8c9d0e1f2
Using API Keys
API Key Scopes
API keys support granular permission scopes. You can grant access to specific resources:Full access to all resources (read and write)
Read-only access to all resources
Resource-Specific Scopes
Bank Accounts
Bank Accounts
bank-accounts.read- Read bank account databank-accounts.write- Create and update bank accounts
Transactions
Transactions
transactions.read- Read transaction datatransactions.write- Create and update transactions
Invoices
Invoices
invoices.read- Read invoice datainvoices.write- Create, update, and delete invoices
Customers
Customers
customers.read- Read customer datacustomers.write- Create and update customers
Documents
Documents
documents.read- Read and download documentsdocuments.write- Upload and delete documents
Time Tracking
Time Tracking
tracker-entries.read- Read time entriestracker-entries.write- Create and update time entriestracker-projects.read- Read projectstracker-projects.write- Create and update projects
Other Resources
Other Resources
teams.read/teams.write- Team managementusers.read/users.write- User managementinbox.read/inbox.write- Inbox managementinsights.read- Financial insightsreports.read- Financial reportstags.read/tags.write- Tag managementsearch.read- Search functionalitychat.read/chat.write- AI chatnotifications.read/notifications.write- Notifications
Managing API Keys
API keys can be managed through the tRPC API:When you create an API key, you’ll receive a notification email with details about the key creation including IP address and timestamp.
OAuth 2.0
OAuth 2.0 is recommended for third-party applications that need to access user data on behalf of users.OAuth Flow
Midday implements the OAuth 2.0 Authorization Code flow with PKCE support:Register Your Application
Create an OAuth application in the Midday dashboard to obtain your
client_id and client_secretStep 1: Authorization Request
Redirect users to the authorization endpoint:Your application’s client ID
URI to redirect to after authorization (must be registered)
Space-separated list of scopes (e.g.,
invoices.read transactions.read)Random string to prevent CSRF attacks
PKCE code challenge (required for public clients)
Must be
S256 if using PKCEStep 2: Handle Authorization Response
After user consent, they’ll be redirected to yourredirect_uri:
Step 3: Exchange Code for Access Token
OAuth Access Tokens
OAuth access tokens have the prefixmid_access_token_ and are valid for 1 hour.
Refreshing Access Tokens
When your access token expires, use the refresh token to obtain a new one:Revoking Tokens
Revoke an access or refresh token when no longer needed:PKCE for Public Clients
PKCE (Proof Key for Code Exchange) is required for public clients (mobile apps, SPAs) and recommended for all OAuth flows.
- Generate a code verifier (random string)
- Create a code challenge:
BASE64URL(SHA256(code_verifier)) - Send
code_challengeandcode_challenge_method=S256in authorization request - Send
code_verifierin token exchange request
Supabase JWT Tokens
If you’re building a custom frontend that uses Supabase authentication, you can use the Supabase JWT token directly:Supabase JWT tokens automatically grant
apis.all scope for authenticated users.Authentication Errors
Invalid or missing authentication credentials
Valid credentials but insufficient permissions
| Error | Description | Solution |
|---|---|---|
Authorization header required | No Authorization header sent | Add Authorization: Bearer <token> header |
Invalid authorization scheme | Wrong scheme used | Use Bearer scheme, not Basic or others |
Token required | Empty token | Provide a valid token after Bearer |
Invalid token format | Token doesn’t match expected format | Check token starts with mid_ |
Invalid API key | API key not found or revoked | Generate a new API key |
User not found | User associated with token doesn’t exist | Contact support |
Invalid or expired access token | OAuth token expired | Refresh the access token |
Security Best Practices
Store Securely
Store API keys in environment variables or secret managers, never in code
Rotate Regularly
Rotate API keys periodically and after any suspected compromise
Use Minimal Scopes
Grant only the minimum scopes needed for your use case
Monitor Usage
Monitor API key usage and check lastUsedAt timestamps