Tokens API
Generate and manage authentication tokens
Overview
The Tokens API allows you to generate secure authentication tokens for embedding Semaphor dashboards or for performing management actions (CRUD) on dashboards and visuals.
There are two types of tokens:
- Dashboard Token: Scoped to a specific dashboard, used for embedding (read-only or self-service).
- Project Token: Scoped to a project, used for management actions (CRUD on dashboards, visuals, etc.).
Token Types
Dashboard Token
- Purpose: Embed a dashboard (read-only or self-service)
- Required fields:
dashboardId
,dashboardSecret
- Optional fields:
- For read-only:
cls
,rcls
,params
,config
- For self-service:
tenantId
,endUserId
,endUserEmail
,displayName
(plus above)
- For read-only:
- Default expiry: 30 minutes (1800 seconds)
Project Token
- Purpose: Management actions (CRUD on dashboards, visuals, etc.)
- Required fields:
type
(must be'project'
)projectId
projectSecret
- Optional fields:
tokenExpiry
- Default expiry: 30 minutes (1800 seconds)
- Note: Project tokens do not support
params
,config
,cls
, orrcls
.
Request Body Reference
Field | Type | Required | For Token Type | Description |
---|---|---|---|---|
type | string | Yes* | project | Required for project token: must be 'project' . For dashboard token, omit or set to 'dashboard' . |
dashboardId | string | Yes* | dashboard | Dashboard ID |
dashboardSecret | string | Yes* | dashboard | Dashboard secret |
projectId | string | Yes* | project | Project ID |
projectSecret | string | Yes* | project | Project secret |
tokenExpiry | integer | No | both | Token expiry in seconds (default: 1800) |
tenantId | string | No | dashboard | Tenant identifier (self-service only) |
endUserId | string | No | dashboard | End user identifier (self-service only) |
endUserEmail | string | No | dashboard | End user email (self-service only) |
orgUserId | string | No | dashboard | Org user identifier (advanced) |
orgUserEmail | string | No | dashboard | Org user email (advanced) |
displayName | string | No | dashboard | Display name (self-service only) |
allowEdit | boolean | No | dashboard | Enable editing (self-service only) |
cls | object/array | No | dashboard | Connection-level security policies |
rcls | object/array | No | dashboard | Row-level security policies |
params | object | No | dashboard | User parameters and preferences |
config | object | No | dashboard | UI configuration options |
*Required for the respective token type.
Example Requests
1. Generate Dashboard Token (Read-Only)
2. Generate Dashboard Token (Self-Service)
3. Generate Project Token (Management)
TypeScript Types
Security Policies & Params
Connection-Level Security (CLS)
Row-Level Security (RCLS)
Multiple Policies
Error Handling & Best Practices
Common token API errors:
Error Code | Description | Solution |
---|---|---|
INVALID_CREDENTIALS | Dashboard ID or secret is incorrect | Verify credentials |
TOKEN_EXPIRED | Token has expired | Generate new token |
INVALID_TOKEN | Token format is invalid | Check token format |
INVALID_SECURITY_POLICY | Security policy configuration is invalid | Review policy syntax |
RATE_LIMIT_EXCEEDED | Too many token requests | Wait before retrying |
Best Practices
1. Token Lifecycle Management
Implement proper token lifecycle management:
2. Multi-Tenant Token Generation
Handle multiple tenants with different configurations:
3. Token Validation
Regularly validate tokens to ensure they're still active:
4. Error Recovery
Implement robust error handling and recovery:
Rate Limits
- Token Generation: 100 requests per minute per dashboard
- Token Validation: 1000 requests per minute per token
- Token Invalidation: 100 requests per minute per token