-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgenerate.ts
More file actions
37 lines (35 loc) · 905 Bytes
/
generate.ts
File metadata and controls
37 lines (35 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { CAT, CommonAccessTokenRenewal } from '../src';
async function main() {
const generator = new CAT({
keys: {
Symmetric256: Buffer.from(
'403697de87af64611c1d32a05dab0fe1fcb715a86ab435f1ec99192d79569388',
'hex'
)
},
expectCwtTag: true
});
const base64encoded = await generator.generate(
{
iss: 'eyevinn',
sub: 'jonas',
aud: 'one',
exp: Math.floor(Date.now() / 1000) + 120,
iat: Math.floor(Date.now() / 1000),
catr: CommonAccessTokenRenewal.fromDict({
type: 'header',
'header-name': 'cta-common-access-token',
expadd: 120,
deadline: 60
}).payload
},
{
type: 'mac',
alg: 'HS256',
kid: 'Symmetric256',
generateCwtId: true // automatically generate a random CWT Id (cti) claim (default: false)
}
);
console.log(base64encoded);
}
main();