Generate Keys
Step 3 - Generate Keys
In this step, you will generate the security key that Talk2sync will use to authenticate requests to your endpoints. This key ensures that only Talk2sync can access your API.
Generate Your Security Key
Procedure
- In the Talk2sync connection configuration interface, locate the "Generate Key" button
- Click the "Generate Key" button
- Talk2sync will create a unique security key for your connection
- Copy and save the generated key in a secure location (you will need it for the next step)
Important: This key will only be displayed once. If you lose it, you will need to generate a new one. Store it securely.
How the Key Works
The security key serves as a bearer token that Talk2sync includes with every request to your endpoints. Your application must validate this key to ensure the request is legitimate.
Implementing Key Validation
Your endpoints must:
- Accept the key in the request header
- Validate that the key matches the one provided by Talk2sync
- Reject any requests with missing or invalid keys
Header Format
Talk2sync will send the security key in the following HTTP header:
Authorization: Bearer {YOUR_GENERATED_KEY}
Or as a custom header (depending on your configuration):
X-Talk2sync-Key: {YOUR_GENERATED_KEY}
Example Implementation
Request from Talk2sync:
GET https://www.example.com/api/products
Authorization: Bearer abc123xyz789...
Your endpoint should:
- Read the
Authorizationheader - Extract the key value after "Bearer "
- Compare it with the stored key
- If valid, process the request
- If invalid, return a
401 Unauthorizedresponse
Validation Response
Your endpoints must include the security key in every response back to Talk2sync:
Response Header:
Authorization: Bearer {YOUR_GENERATED_KEY}
This confirms to Talk2sync that the response is legitimate and comes from your authorized server.
Key Management
- Keep your key secure: Do not share it or commit it to version control
- Rotate keys periodically: Generate new keys as part of your security maintenance
- Use environment variables: Store the key in environment variables, not hardcoded in your application
- Monitor access: Track which requests are made using your key
Example Code (Node.js/Express)
app.use((req, res, next) => {
const authHeader = req.headers.authorization;
const token = authHeader?.split(' ')[1]; // Extract token after "Bearer "
const expectedKey = process.env.TALK2SYNC_KEY;
if (token === expectedKey) {
// Set the key in response headers
res.setHeader('Authorization', `Bearer ${expectedKey}`);
next();
} else {
res.status(401).json({ error: 'Unauthorized' });
}
});
Next Steps
Once you have generated your key and implemented validation in your endpoints, proceed to: Test Your Integration
Related Steps
- Previous: Configure Connection
- Next: Test Your Integration