Server-Side Token Generation
Generate authentication tokens for the ContactsManager SDK
Server-Side Token Generation
To securely authenticate users with the ContactsManager SDK, you need to generate JWT tokens on your server. This guide explains how to create a secure token generation endpoint.
Authentication Flow
- Your app requests a token from your server
- Your server generates a signed JWT token using your API secret
- The server returns the token to your app
- Your app initializes the ContactsManager SDK with the token
This approach keeps your API secret secure by never exposing it in client code.
Token Structure
The JWT token contains the following claims:
Claim | Description |
---|---|
org_id | Your organization ID |
api_key | Your ContactsManager API key |
user_id | The unique identifier for the user |
jti | A unique token identifier (UUID) |
iat | Token issued at timestamp |
exp | Token expiration timestamp |
Implementation Examples
Install the contactsmanager
package for easy token generation.
Install the contactsmanager
package for easy token generation.
Install the @contactsmanager/server
package for easy token generation.
The TypeScript (Deno) example can be deployed as a Supabase Edge Function. This serverless approach provides a secure and scalable way to generate tokens without managing traditional server infrastructure.
Environment Variables
For all implementations, set these environment variables on your server:
Variable | Description |
---|---|
CM_API_KEY | Your ContactsManager API key |
CM_API_SECRET | Your ContactsManager API secret |
CM_ORGANIZATION_ID | Your organization ID |
Security Considerations
- Keep Your API Secret Secure: Never expose your API secret in client-side code
- Set a Reasonable Expiration Time: Balance security and user experience
- Use HTTPS: Always use HTTPS for all API endpoints
- Validate User ID: Ensure the user ID is valid before generating a token
- Implement Rate Limiting: Protect your token endpoint from abuse
Using the Token in your App
Once you have the token from your server, you can use it to initialize the ContactsManager SDK: