@boxyhq/saml-jackson 0.2.4 → 0.3.0-beta.246

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.
Files changed (100) hide show
  1. package/Dockerfile +9 -7
  2. package/README.md +1 -2
  3. package/dist/controller/api.d.ts +32 -0
  4. package/dist/controller/api.js +193 -0
  5. package/dist/controller/error.d.ts +5 -0
  6. package/dist/controller/error.js +12 -0
  7. package/dist/controller/oauth/allowed.d.ts +1 -0
  8. package/dist/controller/oauth/allowed.js +17 -0
  9. package/dist/controller/oauth/code-verifier.d.ts +2 -0
  10. package/dist/controller/oauth/code-verifier.js +15 -0
  11. package/dist/controller/oauth/redirect.d.ts +1 -0
  12. package/dist/controller/oauth/redirect.js +11 -0
  13. package/dist/controller/oauth.d.ts +23 -0
  14. package/dist/controller/oauth.js +263 -0
  15. package/dist/controller/utils.d.ts +6 -0
  16. package/dist/controller/utils.js +17 -0
  17. package/dist/db/db.d.ts +15 -0
  18. package/dist/db/db.js +107 -0
  19. package/dist/db/encrypter.d.ts +3 -0
  20. package/dist/db/encrypter.js +29 -0
  21. package/dist/db/mem.d.ts +20 -0
  22. package/dist/db/mem.js +128 -0
  23. package/dist/db/mongo.d.ts +17 -0
  24. package/dist/db/mongo.js +106 -0
  25. package/dist/db/redis.d.ts +15 -0
  26. package/dist/db/redis.js +107 -0
  27. package/dist/db/sql/entity/JacksonIndex.d.ts +7 -0
  28. package/dist/db/sql/entity/JacksonIndex.js +41 -0
  29. package/dist/db/sql/entity/JacksonStore.d.ts +6 -0
  30. package/dist/db/sql/entity/JacksonStore.js +42 -0
  31. package/dist/db/sql/entity/JacksonTTL.d.ts +4 -0
  32. package/dist/db/sql/entity/JacksonTTL.js +29 -0
  33. package/dist/db/sql/sql.d.ts +20 -0
  34. package/dist/db/sql/sql.js +174 -0
  35. package/dist/db/store.d.ts +5 -0
  36. package/dist/db/store.js +68 -0
  37. package/dist/db/utils.d.ts +7 -0
  38. package/dist/db/utils.js +29 -0
  39. package/dist/env.d.ts +22 -0
  40. package/dist/env.js +35 -0
  41. package/dist/index.d.ts +9 -0
  42. package/dist/index.js +80 -0
  43. package/dist/jackson.d.ts +1 -0
  44. package/dist/jackson.js +153 -0
  45. package/dist/read-config.d.ts +3 -0
  46. package/dist/read-config.js +50 -0
  47. package/dist/saml/claims.d.ts +6 -0
  48. package/dist/saml/claims.js +35 -0
  49. package/dist/saml/saml.d.ts +11 -0
  50. package/dist/saml/saml.js +200 -0
  51. package/dist/saml/x509.d.ts +7 -0
  52. package/dist/saml/x509.js +69 -0
  53. package/dist/typings.d.ts +137 -0
  54. package/dist/typings.js +2 -0
  55. package/package.json +41 -21
  56. package/.dockerignore +0 -2
  57. package/.eslintrc.js +0 -13
  58. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -27
  59. package/.github/ISSUE_TEMPLATE/config.yml +0 -5
  60. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -43
  61. package/.github/pull_request_template.md +0 -31
  62. package/.github/workflows/codesee-arch-diagram.yml +0 -81
  63. package/.github/workflows/main.yml +0 -123
  64. package/_dev/docker-compose.yml +0 -37
  65. package/map.js +0 -1
  66. package/prettier.config.js +0 -4
  67. package/src/controller/api.js +0 -167
  68. package/src/controller/error.js +0 -12
  69. package/src/controller/oauth/allowed.js +0 -19
  70. package/src/controller/oauth/code-verifier.js +0 -16
  71. package/src/controller/oauth/redirect.js +0 -18
  72. package/src/controller/oauth.js +0 -321
  73. package/src/controller/utils.js +0 -19
  74. package/src/db/db.js +0 -81
  75. package/src/db/db.test.js +0 -302
  76. package/src/db/encrypter.js +0 -36
  77. package/src/db/mem.js +0 -111
  78. package/src/db/mongo.js +0 -89
  79. package/src/db/redis.js +0 -88
  80. package/src/db/sql/entity/JacksonIndex.js +0 -42
  81. package/src/db/sql/entity/JacksonStore.js +0 -42
  82. package/src/db/sql/entity/JacksonTTL.js +0 -23
  83. package/src/db/sql/model/JacksonIndex.js +0 -9
  84. package/src/db/sql/model/JacksonStore.js +0 -10
  85. package/src/db/sql/model/JacksonTTL.js +0 -8
  86. package/src/db/sql/sql.js +0 -153
  87. package/src/db/store.js +0 -42
  88. package/src/db/utils.js +0 -30
  89. package/src/env.js +0 -39
  90. package/src/index.js +0 -67
  91. package/src/jackson.js +0 -161
  92. package/src/read-config.js +0 -24
  93. package/src/saml/claims.js +0 -40
  94. package/src/saml/saml.js +0 -223
  95. package/src/saml/x509.js +0 -48
  96. package/src/test/api.test.js +0 -186
  97. package/src/test/data/metadata/boxyhq.js +0 -6
  98. package/src/test/data/metadata/boxyhq.xml +0 -30
  99. package/src/test/data/saml_response +0 -1
  100. package/src/test/oauth.test.js +0 -342
@@ -1,5 +0,0 @@
1
- blank_issues_enabled: false
2
- contact_links:
3
- - name: Questions
4
- url: https://github.com/boxyhq/jackson/discussions
5
- about: Ask a general question about the project on our GitHub Discussion page
@@ -1,43 +0,0 @@
1
- ---
2
- name: Feature request
3
- about: Suggest a feature or idea
4
- title: ""
5
- labels: enhancement
6
- assignees: ""
7
- ---
8
-
9
- > Please check if your Feature Request has not been already raised in the [Discussions Tab](https://github.com/boxyhq/jackson/discussions), as we would like to reduce duplicates. If it has been already raised, simply upvote it 🔼.
10
-
11
- ### Is your proposal related to a problem?
12
-
13
- <!--
14
- Provide a clear and concise description of what the problem is.
15
- For example, "I'm always frustrated when..."
16
- -->
17
-
18
- (Write your answer here.)
19
-
20
- ### Describe the solution you'd like
21
-
22
- <!--
23
- Provide a clear and concise description of what you want to happen.
24
- -->
25
-
26
- (Describe your proposed solution here.)
27
-
28
- ### Describe alternatives you've considered
29
-
30
- <!--
31
- Let us know about other solutions you've tried or researched.
32
- -->
33
-
34
- (Write your answer here.)
35
-
36
- ### Additional context
37
-
38
- <!--
39
- Is there anything else you can add about the proposal?
40
- You might want to link to related issues here, if you haven't already.
41
- -->
42
-
43
- (Write your answer here.)
@@ -1,31 +0,0 @@
1
- ## What does this PR do?
2
-
3
- <!-- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. -->
4
-
5
- Fixes # (issue)
6
-
7
- ## Type of change
8
-
9
- <!-- Please delete options that are not relevant. -->
10
-
11
- - [ ] Bug fix (non-breaking change which fixes an issue)
12
- - [ ] New feature (non-breaking change which adds functionality)
13
- - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
14
- - [ ] This change requires a documentation update
15
-
16
- ## How should this be tested?
17
-
18
- <!-- Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration -->
19
-
20
- - [ ] Test A
21
- - [ ] Test B
22
-
23
- ## Checklist:
24
-
25
- - [ ] My code follows the style guidelines of this project
26
- - [ ] I have performed a self-review of my own code and corrected any misspellings
27
- - [ ] I have commented my code, particularly in hard-to-understand areas
28
- - [ ] I have made corresponding changes to the documentation
29
- - [ ] My changes generate no new warnings
30
- - [ ] I have added tests that prove my fix is effective or that my feature works
31
- - [ ] New and existing unit tests pass locally with my changes
@@ -1,81 +0,0 @@
1
- on:
2
- push:
3
- branches:
4
- - main
5
- pull_request_target:
6
- types: [opened, synchronize, reopened]
7
-
8
- name: CodeSee Map
9
-
10
- jobs:
11
- test_map_action:
12
- runs-on: ubuntu-latest
13
- continue-on-error: true
14
- name: Run CodeSee Map Analysis
15
- steps:
16
- - name: checkout
17
- id: checkout
18
- uses: actions/checkout@v2
19
- with:
20
- repository: ${{ github.event.pull_request.head.repo.full_name }}
21
- ref: ${{ github.event.pull_request.head.ref }}
22
- fetch-depth: 0
23
-
24
- # codesee-detect-languages has an output with id languages.
25
- - name: Detect Languages
26
- id: detect-languages
27
- uses: Codesee-io/codesee-detect-languages-action@latest
28
-
29
- - name: Configure JDK 16
30
- uses: actions/setup-java@v2
31
- if: ${{ fromJSON(steps.detect-languages.outputs.languages).java }}
32
- with:
33
- java-version: '16'
34
- distribution: 'zulu'
35
-
36
- # CodeSee Maps Go support uses a static binary so there's no setup step required.
37
-
38
- - name: Configure Node.js 14
39
- uses: actions/setup-node@v2
40
- if: ${{ fromJSON(steps.detect-languages.outputs.languages).javascript }}
41
- with:
42
- node-version: '14'
43
-
44
- - name: Configure Python 3.x
45
- uses: actions/setup-python@v2
46
- if: ${{ fromJSON(steps.detect-languages.outputs.languages).python }}
47
- with:
48
- python-version: '3.x'
49
- architecture: 'x64'
50
-
51
- - name: Configure Ruby '3.x'
52
- uses: ruby/setup-ruby@v1
53
- if: ${{ fromJSON(steps.detect-languages.outputs.languages).ruby }}
54
- with:
55
- ruby-version: '3.0'
56
-
57
- # CodeSee Maps Rust support uses a static binary so there's no setup step required.
58
-
59
- - name: Generate Map
60
- id: generate-map
61
- uses: Codesee-io/codesee-map-action@latest
62
- with:
63
- step: map
64
- github_ref: ${{ github.ref }}
65
- languages: ${{ steps.detect-languages.outputs.languages }}
66
-
67
- - name: Upload Map
68
- id: upload-map
69
- uses: Codesee-io/codesee-map-action@latest
70
- with:
71
- step: mapUpload
72
- api_token: ${{ secrets.CODESEE_ARCH_DIAG_API_TOKEN }}
73
- github_ref: ${{ github.ref }}
74
-
75
- - name: Insights
76
- id: insights
77
- uses: Codesee-io/codesee-map-action@latest
78
- with:
79
- step: insights
80
- api_token: ${{ secrets.CODESEE_ARCH_DIAG_API_TOKEN }}
81
- github_ref: ${{ github.ref }}
@@ -1,123 +0,0 @@
1
- # This is a basic workflow to help you get started with Actions
2
-
3
- name: CI
4
-
5
- # Controls when the workflow will run
6
- on:
7
- # Triggers the workflow on push or pull request events but only for the main branch
8
- push:
9
- branches:
10
- - '*'
11
- pull_request:
12
- types: [opened, synchronize, reopened]
13
-
14
- # Allows you to run this workflow manually from the Actions tab
15
- workflow_dispatch:
16
-
17
- # A workflow run is made up of one or more jobs that can run sequentially or in parallel
18
- jobs:
19
- publish:
20
- runs-on: ubuntu-latest
21
-
22
- strategy:
23
- matrix:
24
- node-version: [16.x]
25
- # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
26
-
27
- services:
28
- postgres:
29
- image: postgres:13
30
- ports:
31
- - 5432:5432
32
- env:
33
- POSTGRES_PASSWORD: ""
34
- POSTGRES_HOST_AUTH_METHOD: "trust"
35
- # Set health checks to wait until postgres has started
36
- options: >-
37
- --health-cmd pg_isready
38
- --health-interval 10s
39
- --health-timeout 5s
40
- --health-retries 5
41
- redis:
42
- image: redis:6.2.5-alpine
43
- ports:
44
- - 6379:6379
45
- mongo:
46
- image: mongo:4.4.10
47
- ports:
48
- - 27017:27017
49
- mysql:
50
- image: mysql:5.7
51
- ports:
52
- - 3307:3306
53
- env:
54
- MYSQL_DATABASE: mysql
55
- MYSQL_ROOT_PASSWORD: mysql
56
- maria:
57
- image: mariadb:10.4.22
58
- ports:
59
- - 3306:3306
60
- env:
61
- MARIADB_DATABASE: mysql
62
- MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: "yes"
63
-
64
- steps:
65
- - uses: actions/checkout@v2
66
- - name: Use Node.js ${{ matrix.node-version }}
67
- uses: actions/setup-node@v2
68
- with:
69
- always-auth: true
70
- node-version: ${{ matrix.node-version }}
71
- registry-url: https://registry.npmjs.org
72
- scope: '@boxyhq'
73
- cache: 'npm'
74
- - run: npm ci
75
- - run: npm run test
76
- - run: |
77
- publishTag="latest"
78
- if [[ "$GITHUB_REF" == *\/release ]]
79
- then
80
- echo "Release branch"
81
- else
82
- echo "Dev branch"
83
- publishTag="beta"
84
- versionSuffixTag="-beta.${GITHUB_RUN_NUMBER}"
85
- sed "s/\(^[ ]*\"version\"\:[ ]*\".*\)\",/\1${versionSuffixTag}\",/" < package.json > package.json.new
86
- mv package.json.new package.json
87
- fi
88
- npm publish --tag $publishTag --access public
89
- env:
90
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
91
- build:
92
- needs: publish
93
- runs-on: ubuntu-latest
94
-
95
- steps:
96
- - name: Check Out Repo
97
- uses: actions/checkout@v2
98
-
99
- - name: Get short SHA
100
- id: slug
101
- run: echo "::set-output name=sha7::$(echo ${GITHUB_SHA} | cut -c1-7)"
102
-
103
- - name: Set up Docker Buildx
104
- id: buildx
105
- uses: docker/setup-buildx-action@v1
106
-
107
- - name: Login to Docker Hub
108
- uses: docker/login-action@v1
109
- with:
110
- username: ${{ secrets.DOCKER_HUB_USERNAME }}
111
- password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
112
-
113
- - name: Build and push
114
- id: docker_build
115
- uses: docker/build-push-action@v2
116
- with:
117
- context: ./
118
- file: ./Dockerfile
119
- push: true
120
- tags: ${{ github.repository }}:latest,${{ github.repository }}:${{ steps.slug.outputs.sha7 }}
121
-
122
- - name: Image digest
123
- run: echo ${{ steps.docker_build.outputs.digest }}
@@ -1,37 +0,0 @@
1
- # this file is a helper to run all the supported dbs locally, the data is ephemeral since no host volumes will be mounted
2
- version: "3.6"
3
- services:
4
- postgres:
5
- image: postgres:13
6
- ports:
7
- - "5432:5432"
8
- restart: always
9
- environment:
10
- POSTGRES_PASSWORD: ""
11
- POSTGRES_HOST_AUTH_METHOD: trust
12
- redis:
13
- image: redis:6.2.5-alpine
14
- ports:
15
- - "6379:6379"
16
- restart: always
17
- mongo:
18
- image: mongo:4.4.10
19
- ports:
20
- - "27017:27017"
21
- restart: always
22
- mysql:
23
- image: mysql:5.7
24
- ports:
25
- - "3307:3306"
26
- restart: always
27
- environment:
28
- MYSQL_DATABASE: mysql
29
- MYSQL_ROOT_PASSWORD: mysql
30
- maria:
31
- image: mariadb:10.4.22
32
- ports:
33
- - "3306:3306"
34
- restart: always
35
- environment:
36
- MARIADB_DATABASE: mysql
37
- MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: "yes"
package/map.js DELETED
@@ -1 +0,0 @@
1
- module.exports = (test) => test.replace(/\.test\.js$/, '.js');
@@ -1,4 +0,0 @@
1
- module.exports = {
2
- singleQuote: true,
3
- trailingComma: 'es5',
4
- };
@@ -1,167 +0,0 @@
1
- const saml = require('../saml/saml.js');
2
- const x509 = require('../saml/x509.js');
3
- const dbutils = require('../db/utils.js');
4
- const { indexNames } = require('./utils.js');
5
- const { JacksonError } = require('./error.js');
6
-
7
- const crypto = require('crypto');
8
-
9
- let configStore;
10
-
11
- const extractHostName = (url) => {
12
- try {
13
- const pUrl = new URL(url);
14
- if (pUrl.hostname.startsWith('www.')) {
15
- return pUrl.hostname.substring(4);
16
- }
17
- return pUrl.hostname;
18
- } catch (err) {
19
- return null;
20
- }
21
- };
22
-
23
- const config = async (body) => {
24
- const { rawMetadata, defaultRedirectUrl, redirectUrl, tenant, product } =
25
- body;
26
-
27
- if (!rawMetadata) {
28
- throw new JacksonError('Please provide rawMetadata', 400);
29
- }
30
-
31
- if (!defaultRedirectUrl) {
32
- throw new JacksonError('Please provide a defaultRedirectUrl', 400);
33
- }
34
-
35
- if (!redirectUrl) {
36
- throw new JacksonError('Please provide redirectUrl', 400);
37
- }
38
-
39
- if (!tenant) {
40
- throw new JacksonError('Please provide tenant', 400);
41
- }
42
-
43
- if (!product) {
44
- throw new JacksonError('Please provide product', 400);
45
- }
46
-
47
- const idpMetadata = await saml.parseMetadataAsync(rawMetadata);
48
-
49
- // extract provider
50
- let providerName = extractHostName(idpMetadata.entityID);
51
- if (!providerName) {
52
- providerName = extractHostName(
53
- idpMetadata.sso.redirectUrl || idpMetadata.sso.postUrl
54
- );
55
- }
56
-
57
- idpMetadata.provider = providerName ? providerName : 'Unknown';
58
-
59
- let clientID = dbutils.keyDigest(
60
- dbutils.keyFromParts(tenant, product, idpMetadata.entityID)
61
- );
62
- let clientSecret;
63
-
64
- let exists = await configStore.get(clientID);
65
- if (exists) {
66
- clientSecret = exists.clientSecret;
67
- } else {
68
- clientSecret = crypto.randomBytes(24).toString('hex');
69
- }
70
-
71
- const certs = await x509.generate();
72
- if (!certs) {
73
- throw new Error('Error generating x59 certs');
74
- }
75
-
76
- await configStore.put(
77
- clientID,
78
- {
79
- idpMetadata,
80
- defaultRedirectUrl,
81
- redirectUrl: JSON.parse(redirectUrl), // redirectUrl is a stringified array
82
- tenant,
83
- product,
84
- clientID,
85
- clientSecret,
86
- certs,
87
- },
88
- {
89
- // secondary index on entityID
90
- name: indexNames.entityID,
91
- value: idpMetadata.entityID,
92
- },
93
- {
94
- // secondary index on tenant + product
95
- name: indexNames.tenantProduct,
96
- value: dbutils.keyFromParts(tenant, product),
97
- }
98
- );
99
-
100
- return {
101
- client_id: clientID,
102
- client_secret: clientSecret,
103
- provider: idpMetadata.provider,
104
- };
105
- };
106
-
107
- const getConfig = async (body) => {
108
- const { clientID, tenant, product } = body;
109
-
110
- if (clientID) {
111
- const samlConfig = await configStore.get(clientID);
112
- if (!samlConfig) {
113
- return {};
114
- }
115
-
116
- return { provider: samlConfig.idpMetadata.provider };
117
- } else {
118
- const samlConfigs = await configStore.getByIndex({
119
- name: indexNames.tenantProduct,
120
- value: dbutils.keyFromParts(tenant, product),
121
- });
122
- if (!samlConfigs || !samlConfigs.length) {
123
- return {};
124
- }
125
-
126
- return { provider: samlConfigs[0].idpMetadata.provider };
127
- }
128
- };
129
-
130
- const deleteConfig = async (body) => {
131
- const { clientID, clientSecret, tenant, product } = body;
132
-
133
- if (clientID) {
134
- if (!clientSecret) {
135
- throw new JacksonError('Please provide clientSecret', 400);
136
- }
137
- const samlConfig = await configStore.get(clientID);
138
- if (!samlConfig) {
139
- return;
140
- }
141
- if (samlConfig.clientSecret === clientSecret) {
142
- await configStore.delete(clientID);
143
- } else {
144
- throw new JacksonError('clientSecret mismatch', 400);
145
- }
146
- } else {
147
- const samlConfigs = await configStore.getByIndex({
148
- name: indexNames.tenantProduct,
149
- value: dbutils.keyFromParts(tenant, product),
150
- });
151
- if (!samlConfigs || !samlConfigs.length) {
152
- return;
153
- }
154
- for (const conf of samlConfigs) {
155
- await configStore.delete(conf.clientID);
156
- }
157
- }
158
- };
159
-
160
- module.exports = (opts) => {
161
- configStore = opts.configStore;
162
- return {
163
- config,
164
- getConfig,
165
- deleteConfig,
166
- };
167
- };
@@ -1,12 +0,0 @@
1
- class JacksonError extends Error {
2
- constructor(message, statusCode = 500) {
3
- super(message);
4
-
5
- this.name = this.constructor.name;
6
- this.statusCode = statusCode;
7
-
8
- Error.captureStackTrace(this, this.constructor);
9
- }
10
- }
11
-
12
- module.exports = { JacksonError };
@@ -1,19 +0,0 @@
1
- module.exports = {
2
- redirect: (redirectUrl, redirectUrls) => {
3
- const url = new URL(redirectUrl);
4
-
5
- for (const idx in redirectUrls) {
6
- const rUrl = new URL(redirectUrls[idx]);
7
- // TODO: Check pathname, for now pathname is ignored
8
- if (
9
- rUrl.protocol === url.protocol &&
10
- rUrl.hostname === url.hostname &&
11
- rUrl.port === url.port
12
- ) {
13
- return true;
14
- }
15
- }
16
-
17
- return false;
18
- },
19
- };
@@ -1,16 +0,0 @@
1
- const crypto = require('crypto');
2
-
3
- const transformBase64 = (input) => {
4
- return input.replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
5
- };
6
-
7
- const encode = (code_challenge) => {
8
- return transformBase64(
9
- crypto.createHash('sha256').update(code_challenge).digest('base64')
10
- );
11
- };
12
-
13
- module.exports = {
14
- encode,
15
- transformBase64,
16
- };
@@ -1,18 +0,0 @@
1
- module.exports = {
2
- error: (res, redirectUrl, err) => {
3
- var url = new URL(redirectUrl);
4
- url.searchParams.set('error', err);
5
-
6
- res.redirect(url);
7
- },
8
-
9
- success: (redirectUrl, params) => {
10
- const url = new URL(redirectUrl);
11
-
12
- for (const [key, value] of Object.entries(params)) {
13
- url.searchParams.set(key, value);
14
- }
15
-
16
- return url.href;
17
- },
18
- };