Authentication with OAuth 2.0 and PKCE

Login Kit is designed around the OAuth 2.0 authorization code flow with PKCE. Your app never sees a Fentra password, and people see exactly what they're agreeing to.

PlannedLast updated 4 November 2026

The flow at a glance

Fentra already signs people in to its own sites with a “Continue with Fentra” handoff that uses PKCE. Login Kit opens the same pattern to other apps, using standard OAuth 2.0 (RFC 6749) with Proof Key for Code Exchange (RFC 7636).

  1. Your app makes a random code verifier and keeps it.
  2. It sends the person to Fentra's authorization page with the verifier's hash, the code challenge.
  3. The person sees your app and each permission you ask for, and allows or cancels.
  4. Fentra redirects to your redirect URI with a one-time authorization code.
  5. Your server exchanges the code and the verifier for an access token.

PKCE means an intercepted code is useless without the verifier, so the same flow is safe for mobile apps and single-page apps that can't keep a secret.

1. Make a code verifier and challenge

This is standard PKCE and works in any modern browser or in Node with the Web Crypto API.

pkce.tsTypeScript
function base64url(bytes: Uint8Array): string {
  return btoa(String.fromCharCode(...bytes)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
}

export async function pkcePair() {
  const verifier = base64url(crypto.getRandomValues(new Uint8Array(32)));
  const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(verifier));
  return { verifier, challenge: base64url(new Uint8Array(digest)) };
}

Keep the verifier where only this sign-in can reach it: the server-side session, or memory in a native app.

2. Send the person to Fentra

Authorization requestHTTP
GET https://open.fentra.com/v1/oauth/authorize
    ?client_id=YOUR_CLIENT_ID
    &response_type=code
    &scope=user.info.basic,video.list
    &redirect_uri=https://app.example.com/auth/fentra
    &state=af0ifjsldkj
    &code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM
    &code_challenge_method=S256
ParameterWhat it is
client_idYour app's client ID, from registration.
response_typeAlways code.
scopeThe scopes you need, comma-separated. See Scopes.
redirect_uriOne of the redirect URIs registered for your app, matched exactly.
stateA random value you check when the person comes back, to stop cross-site request forgery.
code_challengeThe base64url SHA-256 of your code verifier.
code_challenge_methodAlways S256. Plain challenges won't be accepted.

3. Handle the redirect

If the person allows access, Fentra redirects to your URI with code and your state. If they cancel, it carries error=access_denied instead. Check that state matches before you do anything else.

Redirect back to your appHTTP
GET https://app.example.com/auth/fentra?code=fc_8xLOxBtZp8&state=af0ifjsldkj

4. Exchange the code for a token

Codes are single-use and short-lived. Exchange it from your server.

Token requestHTTP
POST https://open.fentra.com/v1/oauth/token
Content-Type: application/x-www-form-urlencoded

grant_type=authorization_code&code=fc_8xLOxBtZp8&client_id=YOUR_CLIENT_ID&redirect_uri=https://app.example.com/auth/fentra&code_verifier=dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk
Token response (illustrative)JSON
{
  "access_token": "fat_…",
  "token_type": "Bearer",
  "expires_in": 86400,
  "refresh_token": "frt_…",
  "scope": "user.info.basic,video.list",
  "open_id": "fo_4c1d9a0e27b8"
}

open_id identifies the person to your app. It's different for every app, so two apps can't match up the same person by it.

Refreshing and withdrawn access

  • Refresh: when the access token expires, exchange the refresh token for a new pair with grant_type=refresh_token.
  • Withdrawn access: people will be able to remove your app from their Fentra settings at any time. Its tokens stop working at once; treat a 401 as signed out, and delete what you stored. Webhooks are designed to tell you when it happens.
  • Sign out: when someone signs out of your app, revoke their token so it can't be used again.

Security checklist

  • Never put a client secret in a mobile app, a desktop app or a web page.
  • Always use PKCE with S256, even on a server.
  • Check state on every redirect.
  • Register exact redirect URIs over HTTPS. Wildcards won't be accepted.
  • Store tokens encrypted, and never log them.