We use cookies to improve your experience and analyze site traffic. By clicking "Accept", you consent to our use of cookies. See our Privacy Policy for details.

Happy Thanksgiving - 15% off every paid plan Use code THANKYOU at checkout. Ends 30 November.See plans

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.

On this page

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

  1. Redirect the user to https://api.zenflip.io/v1/auth/google.

  1. The user authenticates with Google and grants consent.

  1. Google redirects to https://api.zenflip.io/v1/auth/google/callback.

  1. The API sets httpOnly authentication 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

POST /auth/signup

5 per minute

POST /auth/login

10 per minute

POST /auth/refresh

20 per minute

POST /auth/forgot-password

3 per minute

POST /auth/reset-password

5 per minute

POST /auth/resend-verification

3 per minute

Next →
Quick Start Guide