mirror of
https://github.com/plankanban/planka.git
synced 2025-07-20 21:59:43 +02:00
feat: Additional httpOnly token for enhanced security in browsers
This commit is contained in:
parent
d4043c9726
commit
50519f1bcd
18 changed files with 171 additions and 48 deletions
38
server/api/helpers/utils/create-jwt-token.js
Normal file
38
server/api/helpers/utils/create-jwt-token.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
const { v4: uuid } = require('uuid');
|
||||
const jwt = require('jsonwebtoken');
|
||||
|
||||
module.exports = {
|
||||
sync: true,
|
||||
|
||||
inputs: {
|
||||
subject: {
|
||||
type: 'json',
|
||||
required: true,
|
||||
},
|
||||
issuedAt: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
fn(inputs) {
|
||||
const { issuedAt = new Date() } = inputs;
|
||||
|
||||
const iat = Math.floor(issuedAt / 1000);
|
||||
const exp = iat + sails.config.custom.tokenExpiresIn * 24 * 60 * 60;
|
||||
|
||||
const payload = {
|
||||
iat,
|
||||
exp,
|
||||
sub: inputs.subject,
|
||||
};
|
||||
|
||||
const token = jwt.sign(payload, sails.config.session.secret, {
|
||||
keyid: uuid(),
|
||||
});
|
||||
|
||||
return {
|
||||
token,
|
||||
payload,
|
||||
};
|
||||
},
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue