0.11.12 • Published 4 months ago

@lindorm-io/koa-keystore v0.11.12

Weekly downloads
-
License
AGPL-3.0-or-later
Repository
-
Last release
4 months ago

@lindorm-io/koa-keystore

Keystore middleware for @lindorm-io/koa applications.

Installation

npm install --save @lindorm-io/koa-keystore

Peer Dependencies

This package has the following peer dependencies:

Usage

You will need a middleware that sets keys on context. You can add multiple middleware to add multiple key sources. They will flatten to one array. Once you are done, you will need to initialise the keystore. Add this middleware after all keys have been set.

Keys

Use one or many of these strategies to add keys to context.

JWKS

koaApp.addMiddleware(jwksKeysMiddleware);

Repository Keys

koaApp.addMiddleware(repositoryMiddleware(KeyPairRepository)); // from koa-mongo
koaApp.addMiddleware(repositoryKeysMiddleware);

Cached Repository Keys

koaApp.addWorker(
  keyPairMongoCacheWorker({
    mongoConnection, // not required if mongoConnectionOptions is set
    mongoConnectionOptions: {
      auth: { user: "root", password: "example" },
      databaseName: "database",
      hostname: "mongo.host",
      port: 27000,
    }, // not required if mongoConnection is set
    resisConnection, // not required if redisConnectionOptions is set
    redisConnectionOptions: {
      port: 1000,
      type: RedisConnectionType.CACHE,
    }, // not required if redisConnection is set
    winston: winstonLogger,
    workerInterval: "1 hours",
  }),
);
koaApp.addMiddleware(cacheMiddleware(KeyPairCache)); // from koa-redis
koaApp.addMiddleware(cacheKeysMiddleware);

Cached JWKS

koaApp.addWorker(
  keyPairJwksCacheWorker({
    baseUrl: "https://authentication.service",
    clientName: "Authentication",
    resisConnection, // not required if redisConnectionOptions is set
    redisConnectionOptions: {
      port: 1000,
      type: RedisConnectionType.CACHE,
    }, // not required if redisConnection is set
    winston: winstonLogger,
    workerInterval: "5 minutes",
  }),
);
koaApp.addMiddleware(cacheMiddleware(KeyPairCache)); // from koa-redis
koaApp.addMiddleware(cacheKeysMiddleware);

Keystore

koaApp.addMiddleware(keystoreMiddleware);

Rotation

If you want a worker to handle key rotation automatically, you can let this worker generate keys.

koaApp.addWorker(
  keyPairRotationWorker({
    keyType: KeyType.EC, // optional
    mongoConnection, // not required if mongoConnectionOptions is set
    mongoConnectionOptions: {
      auth: { user: "root", password: "example" },
      databaseName: "database",
      hostname: "mongo.host",
      port: 27000,
    }, // not required if mongoConnection is set
    namedCurve: NamedCurve.P521, // optional
    passphrase: "passphrase", // optional
    rotationInterval: "90 days", // optional
    winston: winstonLogger,
    workerInterval: "1 days",
  }),
);

Cleanup

If you're using key-pairs from repository, you should leave a worker running to clean up expired keys.

koaApp.addWorker(
  keyPairCleanupWorker({
    mongoConnection, // not required if mongoConnectionOptions is set
    mongoConnectionOptions: {
      auth: { user: "root", password: "example" },
      databaseName: "database",
      hostname: "mongo.host",
      port: 27000,
    }, // not required if mongoConnection is set
    winston: winstonLogger,
    workerInterval: "1 days",
  }),
);
0.11.12

4 months ago

0.11.11

5 months ago

0.11.10

5 months ago

0.11.8

6 months ago

0.11.9

5 months ago

0.11.0

6 months ago

0.11.1

6 months ago

0.11.2

6 months ago

0.11.3

6 months ago

0.11.4

6 months ago

0.11.5

6 months ago

0.11.6

6 months ago

0.11.7

6 months ago

0.10.6

6 months ago

0.10.5

11 months ago

0.10.1

1 year ago

0.10.2

1 year ago

0.10.3

1 year ago

0.10.4

1 year ago

0.9.23

1 year ago

0.10.0

1 year ago

0.9.20

1 year ago

0.9.21

1 year ago

0.9.22

1 year ago

0.9.12

1 year ago

0.9.13

1 year ago

0.9.14

1 year ago

0.9.15

1 year ago

0.9.10

1 year ago

0.9.11

1 year ago

0.9.16

1 year ago

0.9.17

1 year ago

0.9.18

1 year ago

0.9.19

1 year ago

0.9.9

1 year ago

0.9.8

2 years ago

0.9.7

2 years ago

0.8.4

2 years ago

0.9.0

2 years ago

0.9.2

2 years ago

0.9.1

2 years ago

0.9.4

2 years ago

0.9.3

2 years ago

0.9.6

2 years ago

0.9.5

2 years ago

0.8.3

2 years ago

0.8.2

2 years ago

0.5.10

2 years ago

0.5.11

2 years ago

0.5.8

2 years ago

0.6.6

2 years ago

0.5.7

2 years ago

0.5.9

2 years ago

0.8.1

2 years ago

0.7.2

2 years ago

0.6.3

2 years ago

0.8.0

2 years ago

0.7.1

2 years ago

0.6.2

2 years ago

0.6.5

2 years ago

0.5.6

2 years ago

0.7.3

2 years ago

0.6.4

2 years ago

0.5.5

2 years ago

0.7.0

2 years ago

0.6.1

2 years ago

0.6.0

2 years ago

0.5.4

2 years ago

0.5.3

2 years ago

0.5.2

2 years ago

0.5.1

2 years ago

0.5.0

3 years ago

0.4.6

3 years ago

0.4.5

3 years ago

0.4.4

3 years ago

0.4.3

3 years ago

0.4.2

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.3.5

3 years ago

0.3.4

3 years ago

0.3.3

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago