Skip to content

Commit

Permalink
Adjusted readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Schmid committed Mar 16, 2017
1 parent af3f229 commit 3c545f3
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,41 @@ _will come_

_will come_

## Examples

### Creating a signed token with node-jwk and njwt

The example uses bluebird promises to be able to catch exceptions thrown in the
key retrieval and lodash for convenience.

```
const time = Math.floor(_.now() / 1000);
const claims = {
iss: 'itsME',
aud: 'myAudience',
iat: time,
exp: time + 3600
};
return BbPromise.try(() => {
const keySet = nodeJWK.JWKSet.fromObject(myPrivateKeySet);
const jwk = keySet.findKeyById(myKeyId);
if (!jwk) {
return BbPromise.reject(new Error('Huh, my key is not there...'));
}
const keyPEM = jwk.key.toPrivateKeyPEM();
const jwt = njwt.create(claims, keyPEM, jwk.alg);
return BbPromise.resolve(jwt.compact());
})
.catch(err => {
return BbPromise.reject(err);
});
```

## Supported key types

RSA, EC, oct
Expand Down

0 comments on commit 3c545f3

Please sign in to comment.