File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,6 +14,41 @@ _will come_
1414
1515_ will come_
1616
17+ ## Examples
18+
19+ ### Creating a signed token with node-jwk and njwt
20+
21+ The example uses bluebird promises to be able to catch exceptions thrown in the
22+ key retrieval and lodash for convenience.
23+
24+ ```
25+ const time = Math.floor(_.now() / 1000);
26+
27+ const claims = {
28+ iss: 'itsME',
29+ aud: 'myAudience',
30+ iat: time,
31+ exp: time + 3600
32+ };
33+
34+ return BbPromise.try(() => {
35+ const keySet = nodeJWK.JWKSet.fromObject(myPrivateKeySet);
36+ const jwk = keySet.findKeyById(myKeyId);
37+
38+ if (!jwk) {
39+ return BbPromise.reject(new Error('Huh, my key is not there...'));
40+ }
41+
42+ const keyPEM = jwk.key.toPrivateKeyPEM();
43+ const jwt = njwt.create(claims, keyPEM, jwk.alg);
44+
45+ return BbPromise.resolve(jwt.compact());
46+ })
47+ .catch(err => {
48+ return BbPromise.reject(err);
49+ });
50+ ```
51+
1752## Supported key types
1853
1954RSA, EC, oct
You can’t perform that action at this time.
0 commit comments