Skip to content

Instantly share code, notes, and snippets.

@spasiu
Created September 7, 2023 15:21
Show Gist options
  • Save spasiu/3d8933e713282ff773d3bc4061e3d4a0 to your computer and use it in GitHub Desktop.
Save spasiu/3d8933e713282ff773d3bc4061e3d4a0 to your computer and use it in GitHub Desktop.
const express = require('express');
const jwt = require('jsonwebtoken');
const app = express();
const PORT = 3000;
const SHARED_SECRET = '';
const ZENDESK_SUBDOMAIN = '';
app.get('/test', (req, res) => {
console.log(JSON.stringify(req.body, null, 4));
const user = {
email: 'user@example.com',
name: 'John Doe'
};
if (!user) {
return res.status(401).send('User not authenticated');
}
const payload = {
iat: Math.floor(Date.now() / 1000),
jti: `${Date.now()}`,
name: user.name,
email: user.email
};
const token = jwt.sign(payload, SHARED_SECRET);
const zendeskUrl = `https://${ZENDESK_SUBDOMAIN}.zendesk.com/access/jwt?jwt=${token}`;
res.redirect(zendeskUrl);
});
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment