@boxyhq/saml-jackson 0.2.3-beta.219 → 0.2.3-beta.224

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boxyhq/saml-jackson",
3
- "version": "0.2.3-beta.219",
3
+ "version": "0.2.3-beta.224",
4
4
  "license": "Apache 2.0",
5
5
  "description": "SAML 2.0 service",
6
6
  "main": "dist/index.js",
@@ -17,12 +17,12 @@
17
17
  ],
18
18
  "scripts": {
19
19
  "build": "tsc -p tsconfig.build.json",
20
- "start": "cross-env IDP_ENABLED=true node src/jackson.js",
21
- "dev": "cross-env IDP_ENABLED=true nodemon src/jackson.js",
22
- "mongo": "cross-env JACKSON_API_KEYS=secret DB_ENGINE=mongo DB_URL=mongodb://localhost:27017/jackson DB_ENCRYPTION_KEY=RiVoTxDoLUUoIUOp224abMxK6PGGfFuF nodemon --config nodemon.json src/jackson.ts",
23
- "sql": "cross-env JACKSON_API_KEYS=secret DB_ENGINE=sql DB_TYPE=postgres DB_URL=postgres://postgres:postgres@localhost:5432/jackson DB_ENCRYPTION_KEY=RiVoTxDoLUUoIUOp224abMxK6PGGfFuF nodemon src/jackson.js",
24
- "pre-loaded": "cross-env JACKSON_API_KEYS=secret DB_ENGINE=mem PRE_LOADED_CONFIG='./_config' nodemon src/jackson.js",
25
- "pre-loaded-db": "cross-env JACKSON_API_KEYS=secret PRE_LOADED_CONFIG='./_config' nodemon src/jackson.js",
20
+ "start": "cross-env IDP_ENABLED=true node dist/jackson.js",
21
+ "dev": "cross-env IDP_ENABLED=true nodemon --config nodemon.json src/jackson.ts",
22
+ "mongo": "cross-env JACKSON_API_KEYS=secret DB_ENGINE=mongo DB_URL=mongodb://localhost:27017/jackson nodemon --config nodemon.json src/jackson.ts",
23
+ "sql": "cross-env JACKSON_API_KEYS=secret DB_ENGINE=sql DB_TYPE=postgres DB_URL=postgres://postgres:postgres@localhost:5432/jackson nodemon --config nodemon.json src/jackson.ts",
24
+ "pre-loaded": "cross-env JACKSON_API_KEYS=secret DB_ENGINE=mem PRE_LOADED_CONFIG='./_config' nodemon --config nodemon.json src/jackson.ts",
25
+ "pre-loaded-db": "cross-env JACKSON_API_KEYS=secret PRE_LOADED_CONFIG='./_config' nodemon --config nodemon.json src/jackson.ts",
26
26
  "test": "tap --ts --timeout=100 src/**/*.test.ts",
27
27
  "dev-dbs": "docker-compose -f ./_dev/docker-compose.yml up -d",
28
28
  "dev-dbs-destroy": "docker-compose -f ./_dev/docker-compose.yml down --volumes --remove-orphans"
@@ -4,8 +4,7 @@ import * as dbutils from '../db/utils';
4
4
  import saml from '../saml/saml';
5
5
  import { JacksonError } from './error';
6
6
  import { IndexNames } from './utils';
7
-
8
- const x509 = require('../saml/x509.js');
7
+ import x509 from '../saml/x509';
9
8
 
10
9
  export class SAMLConfig implements ISAMLConfig {
11
10
  private configStore: Storable;
@@ -1,21 +1,22 @@
1
1
  import crypto from 'crypto';
2
- import * as dbutils from '../db/utils';
3
2
  import {
4
3
  IOAuthController,
4
+ JacksonOption,
5
5
  OAuthReqBody,
6
6
  OAuthTokenReq,
7
7
  OAuthTokenRes,
8
8
  Profile,
9
9
  SAMLResponsePayload,
10
+ Storable,
10
11
  } from 'saml-jackson';
12
+ import * as dbutils from '../db/utils';
13
+ import saml from '../saml/saml';
11
14
  import { JacksonError } from './error';
12
15
  import * as allowed from './oauth/allowed';
13
16
  import * as codeVerifier from './oauth/code-verifier';
14
17
  import * as redirect from './oauth/redirect';
15
18
  import { IndexNames } from './utils';
16
19
 
17
- import saml from '../saml/saml';
18
-
19
20
  const relayStatePrefix = 'boxyhq_jackson_';
20
21
 
21
22
  function getEncodedClientId(
@@ -39,11 +40,11 @@ function getEncodedClientId(
39
40
  }
40
41
 
41
42
  export class OAuthController implements IOAuthController {
42
- private configStore;
43
- private sessionStore;
44
- private codeStore;
45
- private tokenStore;
46
- private opts;
43
+ private configStore: Storable;
44
+ private sessionStore: Storable;
45
+ private codeStore: Storable;
46
+ private tokenStore: Storable;
47
+ private opts: JacksonOption;
47
48
 
48
49
  constructor({ configStore, sessionStore, codeStore, tokenStore, opts }) {
49
50
  this.configStore = configStore;
@@ -133,6 +134,7 @@ export class OAuthController implements IOAuthController {
133
134
  }
134
135
 
135
136
  const samlReq = saml.request({
137
+ // @ts-ignore
136
138
  entityID: this.opts.samlAudience,
137
139
  callbackUrl: this.opts.externalUrl + this.opts.samlPath,
138
140
  signingKey: samlConfig.certs.privateKey,
@@ -188,6 +190,8 @@ export class OAuthController implements IOAuthController {
188
190
 
189
191
  const samlConfigs = await this.configStore.getByIndex({
190
192
  name: IndexNames.EntityID,
193
+
194
+ // @ts-ignore
191
195
  value: parsedResp?.issuer,
192
196
  });
193
197
 
@@ -17,9 +17,12 @@ const mapping = [
17
17
  attribute: 'lastName',
18
18
  schema: 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname',
19
19
  },
20
- ];
20
+ ] as const;
21
21
 
22
- const map = (claims) => {
22
+ type attributes = typeof mapping[number]['attribute'];
23
+ type schemas = typeof mapping[number]['schema'];
24
+
25
+ const map = (claims: Record<attributes | schemas, unknown>) => {
23
26
  const profile = {
24
27
  raw: claims,
25
28
  };
@@ -35,6 +38,4 @@ const map = (claims) => {
35
38
  return profile;
36
39
  };
37
40
 
38
- module.exports = {
39
- map,
40
- };
41
+ export default { map };
@@ -1,5 +1,5 @@
1
- const x509 = require('@peculiar/x509');
2
- const { Crypto } = require('@peculiar/webcrypto');
1
+ import * as x509 from '@peculiar/x509';
2
+ import { Crypto } from '@peculiar/webcrypto';
3
3
 
4
4
  const crypto = new Crypto();
5
5
  x509.cryptoProvider.set(crypto);
@@ -14,16 +14,18 @@ const alg = {
14
14
  const generate = async () => {
15
15
  const keys = await crypto.subtle.generateKey(alg, true, ['sign', 'verify']);
16
16
 
17
- const extensions = [
17
+ const extensions: x509.Extension[] = [
18
18
  new x509.BasicConstraintsExtension(false, undefined, true),
19
19
  ];
20
20
 
21
21
  extensions.push(
22
22
  new x509.KeyUsagesExtension(x509.KeyUsageFlags.digitalSignature, true)
23
23
  );
24
- extensions.push(
25
- await x509.SubjectKeyIdentifierExtension.create(keys.publicKey)
26
- );
24
+ if (keys.publicKey) {
25
+ extensions.push(
26
+ await x509.SubjectKeyIdentifierExtension.create(keys.publicKey)
27
+ );
28
+ }
27
29
 
28
30
  const cert = await x509.X509CertificateGenerator.createSelfSigned({
29
31
  serialNumber: '01',
@@ -34,15 +36,16 @@ const generate = async () => {
34
36
  keys: keys,
35
37
  extensions,
36
38
  });
37
-
38
- const pkcs8 = await crypto.subtle.exportKey('pkcs8', keys.privateKey);
39
-
40
- return {
41
- publicKey: cert.toString('pem'),
42
- privateKey: x509.PemConverter.encode(pkcs8, 'private key'),
43
- };
39
+ if (keys.privateKey) {
40
+ const pkcs8 = await crypto.subtle.exportKey('pkcs8', keys.privateKey);
41
+
42
+ return {
43
+ publicKey: cert.toString('pem'),
44
+ privateKey: x509.PemConverter.encode(pkcs8, 'private key'),
45
+ };
46
+ }
44
47
  };
45
48
 
46
- module.exports = {
49
+ export default {
47
50
  generate,
48
51
  };
File without changes
@@ -25,17 +25,17 @@ const record2 = {
25
25
  city: 'London',
26
26
  };
27
27
 
28
- const memDbConfig: Partial<DatabaseOption> = {
28
+ const memDbConfig = <DatabaseOption>{
29
29
  engine: 'mem',
30
30
  ttl: 1,
31
31
  };
32
32
 
33
- const redisDbConfig: Partial<DatabaseOption> = {
33
+ const redisDbConfig = <DatabaseOption>{
34
34
  engine: 'redis',
35
35
  url: 'redis://localhost:6379',
36
36
  };
37
37
 
38
- const postgresDbConfig: Partial<DatabaseOption> = {
38
+ const postgresDbConfig = <DatabaseOption>{
39
39
  engine: 'sql',
40
40
  url: 'postgresql://postgres:postgres@localhost:5432/postgres',
41
41
  type: 'postgres',
@@ -43,12 +43,12 @@ const postgresDbConfig: Partial<DatabaseOption> = {
43
43
  cleanupLimit: 1,
44
44
  };
45
45
 
46
- const mongoDbConfig: Partial<DatabaseOption> = {
46
+ const mongoDbConfig = <DatabaseOption>{
47
47
  engine: 'mongo',
48
48
  url: 'mongodb://localhost:27017/jackson',
49
49
  };
50
50
 
51
- const mysqlDbConfig: Partial<DatabaseOption> = {
51
+ const mysqlDbConfig = <DatabaseOption>{
52
52
  engine: 'sql',
53
53
  url: 'mysql://root:mysql@localhost:3307/mysql',
54
54
  type: 'mysql',
@@ -56,7 +56,7 @@ const mysqlDbConfig: Partial<DatabaseOption> = {
56
56
  cleanupLimit: 1,
57
57
  };
58
58
 
59
- const mariadbDbConfig: Partial<DatabaseOption> = {
59
+ const mariadbDbConfig = <DatabaseOption>{
60
60
  engine: 'sql',
61
61
  url: 'mariadb://root@localhost:3306/mysql',
62
62
  type: 'mariadb',
@@ -111,7 +111,7 @@ const dbs = [
111
111
 
112
112
  tap.before(async () => {
113
113
  for (const idx in dbs) {
114
- const opts = <DatabaseOption>dbs[idx];
114
+ const opts = dbs[idx];
115
115
  const db = await DB.new(opts);
116
116
 
117
117
  configStores.push(db.store('saml:config'));
@@ -130,8 +130,6 @@ tap.test('dbs', ({ end }) => {
130
130
  let dbEngine = dbs[idx].engine;
131
131
 
132
132
  if (dbs[idx].type) {
133
- // TODO Fix it
134
- // @ts-ignore
135
133
  dbEngine += ': ' + dbs[idx].type;
136
134
  }
137
135
 
@@ -277,10 +275,7 @@ tap.test('dbs', ({ end }) => {
277
275
  });
278
276
 
279
277
  tap.test('ttl expiry: ' + dbEngine, async (t) => {
280
- console.log({ dbEngine });
281
-
282
278
  // mongo runs ttl task every 60 seconds
283
- // @ts-ignore
284
279
  if (dbEngine.startsWith('mongo')) {
285
280
  t.end();
286
281
  return;
@@ -302,9 +297,9 @@ tap.test('dbs', ({ end }) => {
302
297
 
303
298
  tap.test('db.new() error', async (t) => {
304
299
  try {
305
- await DB.new({
306
- engine: 'somedb' as DatabaseEngine,
307
- } as DatabaseOption);
300
+ await DB.new(<DatabaseOption>{
301
+ engine: <DatabaseEngine>'somedb',
302
+ });
308
303
 
309
304
  t.fail('expecting an unsupported db error');
310
305
  } catch (err) {