mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-24 18:32:41 +00:00
This is done in order to have config creation rules unified in one place to avoid modifying them multiple times if they change. We already had 3 duplicated pieces of code initializing the config and there will be more config uses in future tests. This resolves #1960
30 lines
769 B
JavaScript
30 lines
769 B
JavaScript
const jwt = require('jwt-simple');
|
|
|
|
// Load configuration values
|
|
const config = require('./config.js');
|
|
|
|
// Generate an Access Token for the given User ID
|
|
const generateAccessToken = (account)=>{
|
|
const payload = account;
|
|
|
|
// When the token was issued
|
|
payload.issued = (new Date());
|
|
// Which service issued the Token
|
|
payload.issuer = config.get('authentication_token_issuer');
|
|
// Which service is the token intended for
|
|
payload.audience = config.get('authentication_token_audience');
|
|
// The signing key for signing the token
|
|
delete payload.password;
|
|
delete payload._id;
|
|
|
|
const secret = config.get('authentication_token_secret');
|
|
|
|
const token = jwt.encode(payload, secret);
|
|
|
|
return token;
|
|
};
|
|
|
|
module.exports = {
|
|
generateAccessToken : generateAccessToken
|
|
};
|