Token Options
Options for generating an Auth Token to embed a dashboard
Overview
This section outlines the different options available for generating AuthToken
.
AuthToken
is a unique, time-sensitive token that secures access to your dashboard. To generate this token, you need to include DASHBOARD_ID
and DASHBOARD_SECRET
as required fields in the request body, as shown below:
Token Expiry
By default, the AuthToken
is valid for 1 hour. However, you can specify a custom expiry time in the request body. Once the token expires, it will no longer be valid, and you will see a "Session expired" message on the dashboard.
The token expiry is specified in seconds. For example, to set the expiry time to 10 minutes, you can pass tokenExpiry: 60 * 10
in the request body.
This token will remain valid for 10 minutes. This feature is particularly useful if you want to synchronize your application's session timeout with the dashboard, ensuring a seamless and consistent user experience.
You can also explicitly invalidate the token by calling the invalidateToken
function when the user logs out of your application.
The invalidateToken
function sends a POST request to https://semaphor.cloud/api/v1/invalidate-token
to revoke the current session. The request includes the active accessToken
in the Authorization
header.
User Params
In some instances, you may want to pass user specific information to the dashboard. For example, the currency of the user's region. You can pass this information in the params
field in the request body.
Before rendering the currency for the numbers on the dashboard, Semaphor will first check if the currencyFormat
is set in the params
field of the AuthToken
. If it is, Semaphor will use the currency format specified in the params
field. If not, Semaphor will default to the currency format specified in the dashboard settings.
The locale
and the currency
fields must conform to the Intl.NumberFormat format.
Security Policies
The AuthToken
also controls what data user can see in the dashboard. You can set up security policies to restrict the data that a user can access. For more information, see Security & Multi-tenancy section.
Project Tokens
Project tokens provide secure, scoped access to project resources with flexible identity resolution, security policies, and UI configuration options. Unlike dashboard tokens, project tokens are designed for broader access across multiple dashboards within a project.
Project Token Overview
Project tokens are JWT-based authentication tokens that enable:
- Access to multiple dashboards within a project
- Flexible user identity resolution
- Just-in-time (JIT) user provisioning
- Semantic domain restrictions
- Advanced security policies
To generate a project token, you need to include projectId
and projectSecret
as required fields, along with type: 'project'
in the request body:
Identity Resolution
Project tokens support three methods for identifying users:
1. Direct User ID Lookup
When you already have the user ID stored in your system:
2. Email + Tenant Lookup
Identify users by email and tenant association:
3. Just-In-Time (JIT) User Provisioning
Automatically create new users on their first access:
Important Notes about JIT Provisioning:
- The tenant must already exist (new tenants are not created)
- If
autoCreateEndUser
is false or omitted, non-existent users will cause an error - Default role is 'VIEWER' if not specified
- Display name defaults to the email prefix if not provided
Semantic Domain Restrictions
Restrict token access to specific semantic domains within your project. You can use either domain UUIDs or semantic names:
Organization User Authentication
For organization-level users (typically internal users with broader permissions):
Complete Examples
Example 1: Basic Project Token with User Lookup
Example 2: Auto-Provision New User with Domain Restrictions
Example 3: Existing User with Security Policies
Error Handling
Common error messages and their solutions:
Error Message | Cause | Solution |
---|---|---|
"Project ID is required" | Missing projectId | Include projectId in request |
"Project secret is required" | Missing projectSecret | Include projectSecret in request |
"Invalid project credentials" | Wrong projectId or projectSecret | Verify credentials are correct |
"User 'email@example.com' not found in tenant" | User doesn't exist | Set autoCreateEndUser: true or create user first |
"Tenant 'TenantName' not found" | Tenant doesn't exist | Verify tenant name or create tenant first |
"The following semantic domains were not found" | Invalid domain names/IDs | Check domain exists in project |
"User identification required" | No user identification provided | Provide endUserId , orgUserId , or endUserEmail with tenant |
Using TokenRequest
When requesting a token from Semaphor API, you can use the TokenRequest
type to define the request body and customize your analytics experience.
API Endpoint
Request Body
The request body should match the TokenRequest
structure: