The Prisme.ai API uses a robust authentication system to secure access to resources. This guide explains how authentication works and how to implement it in your API requests.

Authentication Methods

JSON Web Tokens (JWTs) are the primary authentication method for web clients and interactive sessions.

1

Obtain a JWT

JWTs are issued in two scenarios:

  1. OpenID Connect (OIDC) authentication: After authenticating with the OIDC server (the api-gateway), clients receive an authorization code that can be exchanged for a JWT. Find your current JWT in the access-token cookie sent to the https://api.studio.prisme.ai/v2/me API after opening any Prisme.ai page
  2. Anonymous authentication: The /v2/login/anonymous endpoint initiates unauthenticated sessions and returns a JWT.
# Example of anonymous login
curl -X POST "https://api.studio.prisme.ai/v2/login/anonymous" \
     -H "Content-Type: application/json"

Response contains a JWT:

{
  "userId": "anon-123456",
  "sessionId": "session-789012",
  "token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtleS0xIn0..."
}
2

Use the JWT

Include the JWT in the Authorization header for API requests:

curl -X GET "https://api.studio.prisme.ai/v2/workspaces" \
     -H "Content-Type: application/json" \
     -H "Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtleS0xIn0..."

JWTs have an expiration time defined by the ACCESS_TOKENS_MAX_AGE setting (default is 30 days). Your application should handle token refreshing or re-authentication when tokens expire.

JWT Token Details

Authentication Flow

  1. Client Authentication: The client authenticates via OIDC or anonymous login to obtain a JWT
  2. API Gateway Validation: Requests are sent to the api-gateway with the JWT or access token
  3. Header Transformation: The api-gateway validates the token and adds an x-prismeai-user-id header
  4. Internal Routing: The request is forwarded to the appropriate microservice with the user context
  5. Authorization Check: The target microservice checks if the authenticated user has the required permissions

Backend microservices rely on the x-prismeai-user-id header for identification. This header should not be directly set in client requests, as it will be overwritten by the api-gateway.

Token Security

Token Storage

  • Store tokens securely (not in localStorage for browser applications)
  • Use HttpOnly cookies where possible
  • For mobile apps, use secure storage mechanisms
  • For server applications, use environment variables or secure vaults

Token Transmission

  • Always use HTTPS/TLS for API communication
  • Use Authorization header rather than query parameters
  • Don’t include tokens in URLs or log them
  • Implement CSRF protection for cookie-based authentication

Token Management

  • Implement token refresh strategies
  • Set appropriate token expiration times
  • Have processes for token revocation
  • Regularly rotate long-lived tokens

Error Handling

  • Handle 401 (Unauthorized) responses properly
  • Don’t expose detailed error information to clients
  • Implement rate limiting for authentication failures
  • Log authentication failures for security monitoring

Authentication Configuration

JWT and authentication behavior can be configured with these environment variables:

VariableDescriptionDefault Value
JWKS_ROTATION_DAYSRotation period in days30
JWKS_KTYJWK Algorithm familyRSA
JWKS_ALGJWK signature algorithmRS256
JWKS_SIZEJWK size2048
ACCESS_TOKENS_MAX_AGEJWT expiration time in seconds2592000 (30 days)

Code Examples

const axios = require('axios');

async function getPrismeData() {
  // Get or refresh your token using your authentication method
  const token = 'YOUR_ACCESS_TOKEN';
  
  try {
    const response = await axios.get('https://api.studio.prisme.ai/v2/workspaces', {
      headers: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${token}`
      }
    });
    
    return response.data;
  } catch (error) {
    if (error.response && error.response.status === 401) {
      // Handle authentication error, potentially refresh token
      console.error('Authentication failed, token may be expired');
    } else {
      console.error('API request failed:', error.message);
    }
    throw error;
  }
}

Next Steps