Skip to content

Commit

Permalink
Making expiration date optional on the JWT.
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorpamplona committed Dec 23, 2021
1 parent e37ef0e commit cec3f92
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/shc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ const URI_SCHEMA = 'shc';
* I am not sure if I should build this by hand.
*/
export async function makeJWT(payload, monthsToExpire, issuer, notBeforeDate) {
let iss = new Date();
let exp = new Date(iss);
let today = new Date();
let exp = new Date(today);
exp.setMonth(exp.getMonth()+monthsToExpire);

let jwt = {
iss: issuer,
iat: Math.round(iss.getTime()/1000),
exp: Math.round(exp.getTime()/1000),
vc: payload
};

if (monthsToExpire) {
jwt['exp'] = Math.round(exp.getTime()/1000)
}

if (notBeforeDate)
jwt['nbf'] = Math.round(notBeforeDate.getTime()/1000);

Expand Down

0 comments on commit cec3f92

Please sign in to comment.