brightspace-auth-keys
![Build Status](https://travis-ci.org/Brightspace/node-auth-keys.svg?branch=master)
Library for generating, storing, and retrieving keypairs for use in
Brightspace's auth framework.
Install
npm install brightspace-auth-keys --save
Usage
Step 1. Implement the interface defined by AbstractPublicKeyStore
:
const AbstractPublicKeyStore = require('brightspace-auth-keys').AbstractPublicKeyStore;
class RedisPublicKeyStore extends AbstractPublicKeyStore {
constructor (redisClient) {
super();
}
_storePublicKey (key, expiry) {
}
_lookupPublicKeys() {
}
}
Step 2. Instantiate KeyGenerator
:
const KeyGenerator = require('brightspace-auth-keys').KeyGenerator;
const publicKeyStore = new RedisPublicKeyStore(...);
const keyGenerator = new KeyGenerator({
signingKeyType: 'EC',
publicKeyStore
});
Step 3. Expose a route for public key retrieval using a routing framework
of your choice. The route will be called by D2L Auth Service. Note that your
service must be known by the Auth service (present in its DB).
const router = require('koa-router')();
router.get('/auth/.well-known/jwks', function() {
return publicKeyStore
.lookupPublicKeys()
.then(keys => this.body = { keys });
});
router.get('/auth/jwk/:kid', function(kid) {
return publicKeyStore
.lookupPublicKey(kid)
.then(key => this.body = key);
});
app.use(router.routes());
Step 4. Instantiate AuthTokenProvisioner providing
keyGenerator.getCurrentPrivateKey
as a keyLookup
function:
const AuthTokenProvisioner = require('brightspace-auth-provisioning');
const provisioner = new AuthTokenProvisioner({
...
keyLookup: keyGenerator.getCurrentPrivateKey.bind(keyGenerator),
...
});
Now you are able to call provisioner.provisionToken(...)
.
Supported options:
const keyGenerator = new KeyGenerator({
signingKeyType: 'EC',
signingKeyAge: 3600,
signingKeyOverlap: 300,
rsa: {
signingKeySize: 2048
},
ec: {
crv: 'P-256'
},
publicKeyStore: new RedisPublicKeyStore(...)
});
Contributing
-
Fork the repository. Committing directly against this repository is
highly discouraged.
-
Make your modifications in a branch, updating and writing new unit tests
as necessary in the test
directory.
-
Ensure that all tests pass with npm test
-
rebase
your changes against master. Do not merge.
-
Submit a pull request to this repository. Wait for tests to run and someone
to chime in.
Code Style
This repository is configured with EditorConfig and
ESLint rules.