clientId from the developer portal). If you haven’t registered yet, start with Quick Ave or the quickstart.
Import paths
| Import | Contents | Runtime |
|---|---|---|
@ave-id/sdk | Core OAuth, PKCE helpers, verifyJwt, fetchJwks | Browser or Node |
@ave-id/sdk/client | startPkceLogin, finishPkceLogin, signIn, signInWithFedCm — browser redirect + FedCM helpers | Browser only |
@ave-id/sdk/expo-session | configureAveSdkForExpo, completeExpoOAuthCallback, AveSession, SecureStore adapter, wireAveSessionToConvex — React Native / Expo (needs expo-crypto for PKCE) | Expo |
@ave-id/sdk/next | AveSessionProvider, useAveSession, AveConvexBridge — Next.js App Router (peer: react) | Browser |
@ave-id/sdk/server | exchangeCodeServer, refreshTokenServer, verifyJwt — uses clientSecret | Server only |
Config object
Most functions take a config object as the first argument:PKCE helpers
generateCodeVerifier()
Generates a cryptographically random PKCE code verifier.
sessionStorage before redirecting and send it as codeVerifier when exchanging the code.
generateCodeChallenge(verifier)
Generates the PKCE code challenge from a verifier using SHA-256.
The code verifier from
generateCodeVerifier().Promise<string> — the base64url-encoded SHA-256 hash. Pass this as codeChallenge to buildAuthorizeUrl.
generateNonce()
Generates a random nonce for ID token replay protection.
nonce to buildAuthorizeUrl and verify it matches the nonce claim in the id_token after exchange.
Authorization functions
buildAuthorizeUrl(config, params)
Builds the URL to redirect users to Ave for sign-in.
Your app’s client ID.
The registered redirect URI the user will be sent to after authorization.
Scopes to request. Available values:
"openid", "profile", "email", "offline_access", "user_id".CSRF protection token. Generate with
crypto.randomUUID(). Store and verify on the callback.ID token replay protection. Generate with
generateNonce(). Verify against the nonce claim in id_token.PKCE challenge from
generateCodeChallenge(). Required for public clients.Optional Ave Business organization ID. When present, Ave verifies that the selected identity belongs to the organization and includes
org_id, org_role, org_scopes, org_signing_authority, org_encryption_mode, org_key_custody, and SSO auth metadata in issued tokens. If the organization requires SSO, the current Ave session must come from that organization’s active SSO connection.Extra query parameters on the Ave sign-in URL. For encrypted invites, set
wrapped_key to the value from encodeWrappedPayloadParam() — see Identity keys & wrapped payloads.exchangeCode(config, payload)
Exchanges an authorization code for tokens. Use for PKCE (public client) flows.
The authorization code from the callback URL.
The PKCE code verifier from
sessionStorage. Required if you used PKCE.refreshToken(config, payload)
Exchanges a refresh token for a new set of tokens.
The refresh token from a previous token response.
fetchUserInfo(config, accessToken)
Fetches live identity claims from the userinfo endpoint.
The opaque
access_token (not the JWT) from the token response.UserInfo with sub, name?, preferred_username?, email?, picture?, and organization? when the token was issued for an Ave Business workspace.
listAveWorkspaceOrganizations(config, accessToken)
Lists Ave Business organizations that the token identity can use. Use it to build a workspace picker before requesting organization context.
id as organizationId to startPkceLogin() or buildAuthorizeUrl().
createAveWorkspaceOrganization(config, accessToken, params)
Creates an Ave Business workspace for the token identity. Call this only after your UI tells the user that it will create an Ave-managed workspace.
organization.id is the organizationId for the follow-up workspace sign-in.
Client helpers
Import from@ave-id/sdk/client. Browser-only.
supportsFedCm()
Checks whether the current browser environment is eligible to attempt FedCM.
signInWithFedCm(params)
Attempts a browser-native FedCM sign-in and returns tokens immediately without a redirect callback.
app_key handoff before resuming automatically.
FedCM does not claim Ave Business organization-context support. Use signIn() or startPkceLogin() with organizationId when signing into a business workspace.
signIn(params)
Smart sign-in helper for browser apps.
It tries FedCM first when available, and falls back to the standard PKCE redirect flow when it isn’t.
FedCmTokenResponsewhen FedCM completes in-pagenullwhen the helper falls back tostartPkceLogin()and redirects the browser
organizationId is present, signIn() uses the PKCE redirect flow so Ave can verify organization membership and SSO policy before issuing tokens.
startPkceLogin(params)
Generates PKCE params, saves them to sessionStorage, and redirects the user to Ave. The browser-friendly alternative to calling generateCodeVerifier + buildAuthorizeUrl + window.location.href manually.
nonce for ID token replay protection, and a state value for CSRF protection — unless you supply your own. All three are stored in sessionStorage and retrieved automatically by finishPkceLogin.
Set organizationId to sign into an Ave Business organization as an app workspace. Ave verifies membership before issuing tokens and includes organization claims in the returned JWTs. See Business workspaces.
finishPkceLogin(options)
Handles the OAuth callback: reads stored PKCE state, verifies the returned state against the stored value, exchanges the authorization code, verifies the returned tokens, and cleans up sessionStorage. Returns null when no code parameter is present — safe to call on every page load.
JWT verification
These functions are available in@ave-id/sdk, @ave-id/sdk/client, and @ave-id/sdk/server.
verifyJwt(token, options?)
Verifies an Ave-issued JWT: parses the token, fetches the OIDC discovery document, validates the RS256 signature against the JWKS, and checks issuer, expiry, audience, and nonce claims. Returns the decoded payload on success or null on any validation failure.
The raw JWT string to verify.
Expected
aud claim. Pass your clientId when verifying id_token. Pass "https://aveid.net" when verifying access_token_jwt.Expected
nonce claim. Pass the nonce you sent in the authorization request to prevent replay attacks.Tolerance in seconds applied to
exp and nbf checks to handle clock drift between servers.Promise<T | null> — the decoded payload typed as T, or null if any check fails (invalid signature, expired, issuer mismatch, audience mismatch, nonce mismatch, or malformed token).
verifyJwt fetches the OIDC discovery document and JWKS automatically and caches both for 5 minutes. For server environments with no global fetch, pass a fetcher option.fetchJwks(options?)
Fetches and caches the Ave JWKS (JSON Web Key Set). Used internally by verifyJwt. Useful if you need direct access to the signing keys.
Server helpers
Import from@ave-id/sdk/server. Server runtime only — requires your clientSecret.
exchangeCodeServer(config, payload)
Same as exchangeCode but uses clientSecret instead of codeVerifier. Use this for confidential clients (server-side token exchange).
refreshTokenServer(config, payload)
Refreshes tokens using client secret (confidential client).
TokenResponse
The shape returned byexchangeCode, exchangeCodeServer, refreshToken, and refreshTokenServer:
Error handling
All SDK functions throw anError when the server returns a non-2xx response. The error message is the error field from the response body (e.g. "invalid_grant", "invalid_client").
See also
- Identity keys and wrapped payloads —
getIdentityKey, envelope decryption, and passing secrets through redirects after OAuth.
