Skip to main content

Exchange Token

Exchange a Supabase JWT token for a MentraOS core token.
This endpoint is used by the mobile app after Supabase authentication.

Endpoint

Request Body

Response

Success (200):
Error (400/401):

Implementation

  • File: packages/cloud/src/routes/auth.routes.ts:19-51
  • Verification: Uses SUPABASE_JWT_SECRET environment variable
  • Token Generation: Signs with AUGMENTOS_AUTH_JWT_SECRET
  • Token Expiry: No explicit expiry set on core token

Core Token Structure

The generated coreToken contains:
  • sub: User ID from Supabase
  • email: User’s email address
  • organizations: Array of user’s organizations
  • defaultOrg: User’s default organization

Generate Webview Token

Generate a temporary token for webview authentication within apps.

Endpoint

Headers

Request Body

Response

Implementation

  • File: packages/cloud/src/routes/auth.routes.ts:54-69
  • Middleware: validateCoreToken - Validates the core JWT token
  • Service: Uses tokenService.generateTemporaryToken()

Exchange User Token

Exchange a temporary token for user details (called by app backends).

Endpoint

Headers

The validateAppApiKey middleware extracts the API key from the Authorization header.

Request Body

Response

Success:
Error:

Implementation

  • File: packages/cloud/src/routes/auth.routes.ts:72-93
  • Middleware: validateAppApiKey - Validates app API key
  • Service: Uses tokenService.exchangeTemporaryToken()

Exchange Store Token

Special endpoint for the MentraOS Store webview to get full tokens.

Endpoint

Request Body

Response

Implementation

  • File: packages/cloud/src/routes/auth.routes.ts:96-145
  • Validation: Only accepts packageName: "org.augmentos.store"
  • Returns: Both Supabase and core tokens for full authentication

Hash with API Key

Create a hash using an app’s API key (for secure client-side verification).

Endpoint

Headers

Request Body

Response

Implementation

  • File: packages/cloud/src/routes/auth.routes.ts:148-162
  • Service: Uses appService.hashWithApiKey()
  • Purpose: Allows apps to verify data integrity

Generate Signed User Token

Generate a signed JWT token for webview authentication in apps.

Endpoint

Headers

Request Body

Response

Implementation

  • File: packages/cloud/src/routes/auth.routes.ts:176-199
  • Service: Uses tokenService.issueUserToken()
  • Signing: Uses RSA private key for client-side verification
  • Expiration: 10 minutes

Error Codes

Security Notes

  1. All tokens should be transmitted over HTTPS
  2. Core tokens expire after a configured duration
  3. Temporary tokens are single-use and expire quickly
  4. API keys must be kept secret and never exposed client-side