-
Notifications
You must be signed in to change notification settings - Fork 0
/
getauth.js
42 lines (39 loc) · 1.15 KB
/
getauth.js
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
38
39
40
41
42
'use strict';
const fs = require('fs');
const jwt = require('jsonwebtoken');
const uuid4 = require('uuid4');
var privateKEY = fs.readFileSync('./../certs/privateKeySigning.key', 'utf8');
var publicKEY = fs.readFileSync('./../certs/publicKeySigning.pem', 'utf8');
/*
==================== JWT Signing =====================
*/
var id = uuid4();
var payload = {
"token_endpoint_auth_signing_alg": "PS256",
"jti": id
};
var header = {"alg":"PS256", "typ":"JWT", "kid":"5FZT6gTLM5wEoSGn3eW0Q8zCPsQ"};
var issuer = 'ClientId';
var subject = 'ClientId';
var audience = 'https://tsob.sainsburysbank.co.uk:443/sso/oauth2/realms/root/realms/general';
var signOptions = {
issuer: issuer,
header: header,
subject: subject,
audience: audience,
expiresIn: "1h"
};
var token = jwt.sign(payload, privateKEY, signOptions);
console.log("Token :" + token);
/*
==================== JWT Verify =====================
*/
var verifyOptions = {
issuer: issuer,
subject: subject,
audience: audience,
expiresIn: "1h",
algorithm: ["PS256"]
};
var legit = jwt.verify(token, publicKEY, verifyOptions);
console.log("\nJWT verification result: " + JSON.stringify(legit));