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: Access to multiple dashboards within a project with flexible user management
- Required fields:
type
(must be'project'
)projectId
projectSecret
- User identification (one required):
endUserId
- Direct user ID lookupendUserEmail
+ (tenantId
ortenantName
) - Email-based lookuporgUserId
- Organization user lookup
- Optional fields:
tokenExpiry
- Token expiration in secondsautoCreateEndUser
- Enable JIT user provisioningrole
- User role ('VIEWER' or 'POWER_USER')displayName
- Display name for usersinitialDashboardId
- Initial dashboard to loadallowedSemanticDomains
- Array of domain IDs or namesallowEdit
- Enable self-service editingcls
,rcls
,sls
- Security policiesparams
,config
- UI customization
- Default expiry: 30 minutes (1800 seconds)
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 | both | Tenant identifier |
tenantName | string | No | project | Tenant name (alternative to tenantId) |
endUserId | string | No | both | End user identifier |
endUserEmail | string | No | both | End user email |
orgUserId | string | No | both | Org user identifier |
orgUserEmail | string | No | dashboard | Org user email |
displayName | string | No | both | Display name for user |
autoCreateEndUser | boolean | No | project | Auto-create users if they don't exist |
role | string | No | project | Role for auto-created users ('VIEWER' or 'POWER_USER') |
initialDashboardId | string | No | project | Initial dashboard to load |
allowedSemanticDomains | array | No | project | Array of semantic domain IDs or names |
allowEdit | boolean | No | both | Enable self-service editing |
cls | object/array | No | both | Connection-level security policies |
rcls | object/array | No | both | Row-level security policies |
sls | string | No | project | Schema-level security policy |
params | object | No | both | User parameters and preferences |
config | object | No | both | UI configuration options |
*Required for the respective token type.
Example Requests
1. Generate Dashboard Token (Read-Only)
2. Generate Project Token (Basic)
3. Generate Project Token with JIT User Provisioning
4. Generate Project Token with Semantic Domains
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