Authentication
Learn how to authenticate with the ZenFlip API using JWT tokens, cookie-based token refresh, Google OAuth, and API keys for server-to-server communication.
Authentication
The ZenFlip API supports two authentication methods: email/password login (JWT tokens) and Google OAuth. API keys are available for server-to-server communication. All protected endpoints require a valid Bearer token in the Authorization header.
Email and Password Login
Sign Up
Create a new account and organization:
After signup, a verification email is sent. The account must be verified before full access is granted.
Login
Exchange credentials for JWT tokens:
Response:
The accessToken expires after the number of seconds indicated by expiresIn (default: 3600 seconds / 1 hour).
The refresh token is not included in the response body. It is set as an httpOnly cookie, which browsers send automatically to the refresh endpoint and scripts cannot read. That keeps a long-lived credential out of reach of any script running on the page.
Using Tokens
Include the access token in the Authorization header for all protected requests:
Using JavaScript fetch:
Token Refresh
When the access token expires, call the refresh endpoint to get a new one without prompting the user to log in again. In a browser, send the request with credentials included so the refresh cookie goes with it:
Response:
The response contains a new accessToken. The refresh token is rotated on every call, and the new one replaces the old cookie; the previous refresh token stops working. Each sign-in is a separate session, so signing out, or revoking the session under Settings → Sessions, ends it on every device that holds its tokens.
For server-to-server integrations, which cannot keep cookies, use an API key instead of the login and refresh flow (see below).
JavaScript Refresh Example
Google OAuth
ZenFlip supports Google OAuth for single sign-on. This flow is browser-based and uses server-side redirects.
Flow
Redirect the user to
https://api.zenflip.io/v1/auth/google.
The user authenticates with Google and grants consent.
Google redirects to
https://api.zenflip.io/v1/auth/google/callback.
The API sets
httpOnlyauthentication cookies and redirects the user to your frontend callback URL (e.g.,https://app.zenflip.io/auth/google/callback?isNew=0).
The isNew parameter indicates whether a new account was created (1) or the user logged into an existing account (0). Your frontend reads this flag to decide whether to show onboarding.
Integration Example
After the OAuth callback, the user's browser has authentication cookies set. Subsequent API calls from the browser will be authenticated via those cookies.
API Keys (Server-to-Server) {#api-keys}
For backend integrations, scripts and CI/CD pipelines, use an API key rather than the login and refresh flow. Create one under Settings → API Keys (Business plan and above) and send it with each request as Authorization: Bearer <your key>. API keys do not expire with a session, so store them as a secret on your server and never in browser code.
Email Verification
New accounts require email verification. The API provides endpoints for verifying and resending the verification email:
Password Reset
If a user forgets their password, initiate a reset flow:
Current User Profile
Retrieve the authenticated user's profile:
Logout
Invalidate the current session and clear cookies:
Rate Limits
Authentication endpoints have their own rate limits to prevent abuse:
Endpoint | Limit |
|---|---|
| 5 per minute |
| 10 per minute |
| 20 per minute |
| 3 per minute |
| 5 per minute |
| 3 per minute |