Skip to content

Instantly share code, notes, and snippets.

@louicoder
Created November 4, 2019 09:48
Show Gist options
  • Save louicoder/1d99e64fcb32b5a3f1dbda633a938a44 to your computer and use it in GitHub Desktop.
Save louicoder/1d99e64fcb32b5a3f1dbda633a938a44 to your computer and use it in GitHub Desktop.
const app = require('express')(),
env = require('dotenv').config(),
JWT = require('jsonwebtoken'),
bodyParser = require('body-parser');
// support parsing of application/json type post data
app.use(bodyParser.json());
//support parsing of application/x-www-form-urlencoded post data
app.use(bodyParser.urlencoded({ extended: true }));
app.post('/token', (req, res) => {
const payload = {
userType: req.body.userType || ''
};
// console.log('env', env.parsed.AUTHY_SECRET); // This can be any in any environmental variable for yonja
const Token = JWT.sign(payload, env.parsed.AUTHY_SECRET, {
algorithm: 'HS256',
expiresIn: '24h',
subject: 'authy_verification'
});
return res.json({ Token });
});
app.listen(env.parsed.PORT || 3000, function () {
console.log('Server is running at 3000');
});
@louicoder
Copy link
Author

louicoder commented Nov 4, 2019

Create env file and add AUTHY_SECRET and its value like [AUTHY_SECRET=xxxxxxxxxxxxxx] and another key PORT like [PORT=3000].

@louicoder
Copy link
Author

We can also change the subject to be dynamic and be passed through the body @v1b3m

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment