MCPcopy
hub / github.com/auth0/node-jsonwebtoken / signJWTHelper

Function signJWTHelper

test/test-utils.js:96–118  ·  view source on GitHub ↗

* Sign a payload to create a JWT, ensuring that the asynchronous and synchronous calls to `sign` have the same result * @param {object} payload The JWT payload * @param {string} secretOrPrivateKey The shared secret or private key * @param {object} options Sign options * @param {function(err, tok

(payload, secretOrPrivateKey, options, callback)

Source from the content-addressed store, hash-verified

94 * @param {function(err, token):void} callback
95 */
96function signJWTHelper(payload, secretOrPrivateKey, options, callback) {
97 // freeze the time to ensure the clock remains stable across the async and sync calls
98 const fakeClock = sinon.useFakeTimers({now: Date.now()});
99 let error;
100 let syncSigned;
101 try {
102 syncSigned = jwt.sign(payload, secretOrPrivateKey, options);
103 }
104 catch (err) {
105 error = err;
106 }
107 jwt.sign(payload, secretOrPrivateKey, options, (err, asyncSigned) => {
108 fakeClock.restore();
109 if (error) {
110 expectEqualError(err, error);
111 callback(err);
112 }
113 else {
114 expect(syncSigned, 'Async/Sync token equality').to.equal(asyncSigned);
115 callback(null, syncSigned);
116 }
117 });
118}
119
120module.exports = {
121 asyncCheck,

Callers

nothing calls this directly

Calls 2

expectEqualErrorFunction · 0.85
callbackFunction · 0.85

Tested by

no test coverage detected