Created
September 7, 2023 15:21
-
-
Save spasiu/3d8933e713282ff773d3bc4061e3d4a0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: '[email protected]', | |
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