Overview
The authorization code flow with PKCE (Proof Key for Code Exchange) is the recommended method for authenticating users with Ave. This flow ensures secure authentication even for public clients like single-page applications and mobile apps.Flow Diagram
Generate PKCE parameters
Create a code verifier and code challenge to secure the authorization flow.
Build authorization URL
Construct the authorization URL with your app’s configuration and PKCE parameters.
Redirect user to Ave
Redirect the user to the authorization URL. They will see the Ave authorization screen.The user will be redirected to:
User authorizes your app
The user sees your app’s information and selects which Ave identity to use for authorization. After granting permission, Ave redirects back to your
redirect_uri with an authorization code.Authorization Endpoint
POST /api/oauth/authorize
This endpoint requires user authentication and creates an authorization code. Headers:400- Invalid client_id, redirect_uri, or scope400- Identity doesn’t belong to user400- E2EE app requires encryptedAppKey
SDK Functions
generateCodeVerifier()
Generates a cryptographically random code verifier for PKCE.generateCodeChallenge()
Generates a code challenge from a code verifier using SHA-256.generateNonce()
Generates a random nonce for replay protection.buildAuthorizeUrl()
Constructs the authorization URL for redirecting users.exchangeCode()
Exchanges an authorization code for access tokens.Security Best Practices
Always use PKCE
Always use PKCE
Even for confidential clients, PKCE adds an extra layer of security. Always use
S256 as the code challenge method, never plain.Validate state parameter
Validate state parameter
The
state parameter protects against CSRF attacks. Generate a random value, store it securely, and verify it matches when handling the callback.Use nonce for OIDC
Use nonce for OIDC
When requesting the
openid scope, include a nonce parameter to prevent replay attacks. Verify the nonce claim in the ID token matches your original value.Store code verifier securely
Store code verifier securely
The code verifier is sensitive. Store it in sessionStorage or a secure cookie, never in localStorage or URL parameters.
Validate redirect URIs
Validate redirect URIs
Only use redirect URIs that are registered with your OAuth app. Ave will reject authorization requests with unregistered URIs.
Common Errors
| Error Code | Description | Solution |
|---|---|---|
invalid_client | Client ID not found | Verify your clientId is correct |
invalid_scope | Requested scope not allowed | Check your app’s allowed scopes |
invalid_grant | Authorization code invalid/expired | Codes expire after 10 minutes |
invalid_request | Missing required parameter | Check all required fields are provided |
Next Steps
Token Exchange
Learn how to refresh tokens and handle token expiration