Integrate Tooken tokens with your CI/CD and services
Store and consume Tooken API tokens securely across CI/CD pipelines, environment variables, cloud secrets managers, and webhook-driven rotation workflows.
Tooken tokens are standard Bearer credentials — any HTTP client that can set an Authorization header can use them. The patterns below cover the most common integration scenarios: injecting tokens into CI/CD pipelines, reading them from environment variables in application code, storing them in a secrets manager, and automating rotation in response to webhook events.
Never hard-code a token secret in source code, configuration files, or Docker images. Store secrets in environment variables or a dedicated secrets manager and inject them at runtime.
Create a dedicated token for each CI/CD workflow with only the scopes that workflow requires. If the token is ever exposed in logs, you can revoke just that credential without affecting other services.
To add the secret in GitHub, go to your repository’s Settings → Secrets and variables → Actions and click New repository secret.
Reading the token from an environment variable keeps the secret out of your source code and makes it easy to swap credentials between environments (development, staging, production) without changing code.
// Read the Tooken token from the environment at startup.// Set TOOKEN_TOKEN in your .env file (for local development)// or in your hosting platform's environment configuration.const TOOKEN_TOKEN = process.env.TOOKEN_TOKEN;if (!TOOKEN_TOKEN) { throw new Error('TOOKEN_TOKEN environment variable is not set.');}async function listTokens() { const response = await fetch('https://api.tooken.io/v1/tokens', { headers: { 'Authorization': `Bearer ${TOOKEN_TOKEN}`, }, }); if (!response.ok) { throw new Error(`Tooken API error: ${response.status}`); } return response.json();}
For local development, use a .env file and load it with a library such as dotenv (Node.js) or python-dotenv (Python). Add .env to your .gitignore to prevent the file from being committed.
.env
TOOKEN_TOKEN=tok_live_xxxxxxxxxxxxxxxxxxxx
Use different tokens for each environment. Name them to match — for example, api-server-dev, api-server-staging, and api-server-prod — so you can immediately identify which token is in use from the dashboard and audit log.
For production workloads, store your Tooken token in a dedicated secrets manager so it benefits from access controls, versioning, and audit trails provided by that platform.
vault kv put secret/tooken/my-service-token token="tok_live_xxxxxxxxxxxxxxxxxxxx"
Read it at runtime:
vault cli
vault kv get -field=token secret/tooken/my-service-token
Grant your application’s IAM role or Vault policy read-only access to the specific secret path. Avoid using broad wildcard policies that would allow reading unrelated secrets.
When you rotate a Tooken token, Tooken emits a token.rotated webhook event containing the token ID. You can listen for this event and automatically retrieve the new secret from Tooken, then update your secrets store — removing the need for a separate cron job.Configure a webhook endpoint in the Tooken dashboard or via the API. See Webhooks configuration for setup instructions.Your webhook receiver should:
Validate the incoming request using the webhook signature.
Check the event type — handle only token.rotated events.
Fetch the updated token record (note: the secret is not included in the webhook payload — you must call POST /tokens/:id/rotate programmatically or retrieve the secret from wherever you stored it at rotation time).
Update the secret in your secrets manager.
Trigger a rolling restart of dependent services.
webhook-receiver.js
import express from 'express';import crypto from 'crypto';const app = express();app.use(express.json());const WEBHOOK_SECRET = process.env.TOOKEN_WEBHOOK_SECRET;app.post('/webhooks/tooken', async (req, res) => { // 1. Validate the webhook signature const signature = req.headers['x-tooken-signature']; const expected = crypto .createHmac('sha256', WEBHOOK_SECRET) .update(JSON.stringify(req.body)) .digest('hex'); if (signature !== `sha256=${expected}`) { return res.status(401).json({ error: 'Invalid signature' }); } const { type, data } = req.body; // 2. Handle the token.rotated event if (type === 'token.rotated') { const { id: tokenId } = data; console.log(`Token ${tokenId} was rotated — update dependent services.`); // 3. Update your secrets store and restart services here // await updateSecretsManager(tokenId, newSecret); // await triggerRollingRestart(); } res.status(200).json({ received: true });});app.listen(3000);
Store the new secret in your secrets manager immediately after calling the rotate endpoint — before the webhook fires. That way, your webhook handler can simply trigger a restart and your service will pick up the already-updated secret.