@boxyhq/saml-jackson 0.1.5 → 0.2.0-beta.149
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/.github/ISSUE_TEMPLATE/bug_report.md +27 -0
- package/.github/ISSUE_TEMPLATE/config.yml +5 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +43 -0
- package/.github/pull_request_template.md +31 -0
- package/.github/workflows/main.yml +1 -1
- package/README.md +222 -80
- package/package.json +21 -12
- package/src/controller/api.js +47 -0
- package/src/controller/error.js +12 -0
- package/src/controller/oauth/redirect.js +4 -3
- package/src/controller/oauth.js +48 -60
- package/src/controller/utils.js +11 -0
- package/src/db/db.test.js +1 -1
- package/src/db/sql/entity/JacksonIndex.js +2 -0
- package/src/db/sql/entity/JacksonStore.js +28 -16
- package/src/db/sql/entity/JacksonTTL.js +23 -0
- package/src/db/sql/model/JacksonStore.js +1 -2
- package/src/db/sql/model/JacksonTTL.js +8 -0
- package/src/db/sql/sql.js +45 -21
- package/src/db/utils.js +5 -4
- package/src/env.js +3 -0
- package/src/index.js +3 -2
- package/src/jackson.js +63 -9
- package/src/saml/claims.js +40 -0
- package/src/saml/saml.js +29 -3
- package/src/test/data/metadata/boxyhq.js +6 -0
- package/src/test/data/metadata/boxyhq.xml +30 -0
- package/src/test/data/saml_response +1 -0
- package/src/test/oauth.test.js +342 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
---
|
2
|
+
name: Bug report
|
3
|
+
about: Report any issues with the platform
|
4
|
+
title: ""
|
5
|
+
labels: bug
|
6
|
+
assignees: ""
|
7
|
+
---
|
8
|
+
|
9
|
+
Found a bug? Please fill out the sections below. 👍
|
10
|
+
|
11
|
+
### Issue Summary
|
12
|
+
|
13
|
+
A summary of the issue. This needs to be a clear detailed-rich summary.
|
14
|
+
|
15
|
+
### Steps to Reproduce
|
16
|
+
|
17
|
+
1. (for example) Went to ...
|
18
|
+
2. Clicked on...
|
19
|
+
3. ...
|
20
|
+
|
21
|
+
Any other relevant information. For example, why do you consider this a bug and what did you expect to happen instead?
|
22
|
+
|
23
|
+
### Technical details
|
24
|
+
|
25
|
+
- Browser version: You can use https://www.whatsmybrowser.org/ to find this out.
|
26
|
+
- Node.js version
|
27
|
+
- Anything else that you think could be an issue.
|
@@ -0,0 +1,43 @@
|
|
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.)
|
@@ -0,0 +1,31 @@
|
|
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
|
package/README.md
CHANGED
@@ -4,22 +4,34 @@ SAML service [SAML in a box from BoxyHQ]
|
|
4
4
|
|
5
5
|
You need someone like Jules Winnfield to save you from the vagaries of SAML login.
|
6
6
|
|
7
|
-
|
7
|
+
# Source code visualizer
|
8
|
+
|
8
9
|
[CodeSee codebase visualizer](https://app.codesee.io/maps/public/53e91640-23b5-11ec-a724-79d7dd589517)
|
9
10
|
|
10
|
-
#
|
11
|
-
|
11
|
+
# Getting Started
|
12
|
+
|
13
|
+
There are two ways to use this repo.
|
14
|
+
|
15
|
+
- As an npm library (for Express compatible frameworks)
|
16
|
+
- As a separate service
|
17
|
+
|
18
|
+
## Install as an npm library
|
19
|
+
|
20
|
+
Jackson is available as an [npm package](https://www.npmjs.com/package/@boxyhq/saml-jackson) that can be integrated into any web application framework (like Express.js for example). Please file an issue or submit a PR if you encounter any issues with your choice of framework.
|
21
|
+
|
22
|
+
```
|
23
|
+
npm i @boxyhq/saml-jackson
|
24
|
+
```
|
12
25
|
|
13
|
-
|
26
|
+
### Add Express Routes
|
14
27
|
|
15
|
-
Here's how to use the npm library:
|
16
28
|
```
|
17
29
|
// express
|
18
30
|
const express = require('express');
|
19
31
|
const router = express.Router();
|
20
32
|
const cors = require('cors'); // needed if you are calling the token userinfo endpoints from the frontend
|
21
33
|
|
22
|
-
// Set the required options
|
34
|
+
// Set the required options. Refer to https://github.com/boxyhq/jackson#configuration for the full list
|
23
35
|
const opts = {
|
24
36
|
externalUrl: 'https://my-cool-app.com',
|
25
37
|
samlAudience: 'https://my-cool-app.com',
|
@@ -27,15 +39,18 @@ const opts = {
|
|
27
39
|
db: {
|
28
40
|
engine: 'mongo',
|
29
41
|
url: 'mongodb://localhost:27017/my-cool-app',
|
30
|
-
}
|
42
|
+
}
|
31
43
|
};
|
32
44
|
|
45
|
+
|
46
|
+
let apiController;
|
47
|
+
let oauthController;
|
33
48
|
// Please note that the initialization of @boxyhq/saml-jackson is async, you cannot run it at the top level
|
34
49
|
// Run this in a function where you initialise the express server.
|
35
50
|
async function init() {
|
36
51
|
const ret = await require('@boxyhq/saml-jackson')(opts);
|
37
|
-
|
38
|
-
|
52
|
+
apiController = ret.apiController;
|
53
|
+
oauthController = ret.oauthController;
|
39
54
|
}
|
40
55
|
|
41
56
|
// express.js middlewares needed to parse json and x-www-form-urlencoded
|
@@ -60,102 +75,108 @@ router.post('/api/v1/saml/config', async (req, res) => {
|
|
60
75
|
// OAuth 2.0 flow
|
61
76
|
router.get('/oauth/authorize', async (req, res) => {
|
62
77
|
try {
|
63
|
-
await oauthController.authorize(req
|
78
|
+
const { redirect_url } = await oauthController.authorize(req.query);
|
79
|
+
|
80
|
+
res.redirect(redirect_url);
|
64
81
|
} catch (err) {
|
65
|
-
|
82
|
+
const { message, statusCode = 500 } = err;
|
83
|
+
|
84
|
+
res.status(statusCode).send(message);
|
66
85
|
}
|
67
86
|
});
|
68
87
|
|
69
88
|
router.post('/oauth/saml', async (req, res) => {
|
70
89
|
try {
|
71
|
-
await oauthController.samlResponse(req
|
90
|
+
const { redirect_url } = await oauthController.samlResponse(req.body);
|
91
|
+
|
92
|
+
res.redirect(redirect_url);
|
72
93
|
} catch (err) {
|
73
|
-
|
94
|
+
const { message, statusCode = 500 } = err;
|
95
|
+
|
96
|
+
res.status(statusCode).send(message);
|
74
97
|
}
|
75
98
|
});
|
76
99
|
|
77
100
|
router.post('/oauth/token', cors(), async (req, res) => {
|
78
101
|
try {
|
79
|
-
await oauthController.token(req
|
102
|
+
const result = await oauthController.token(req.body);
|
103
|
+
|
104
|
+
res.json(result);
|
80
105
|
} catch (err) {
|
81
|
-
|
106
|
+
const { message, statusCode = 500 } = err;
|
107
|
+
|
108
|
+
res.status(statusCode).send(message);
|
82
109
|
}
|
83
110
|
});
|
84
111
|
|
85
|
-
router.get('/oauth/userinfo',
|
112
|
+
router.get('/oauth/userinfo', async (req, res) => {
|
86
113
|
try {
|
87
|
-
|
114
|
+
let token = extractAuthToken(req);
|
115
|
+
|
116
|
+
// check for query param
|
117
|
+
if (!token) {
|
118
|
+
token = req.query.access_token;
|
119
|
+
}
|
120
|
+
|
121
|
+
if (!token) {
|
122
|
+
res.status(401).json({ message: 'Unauthorized' });
|
123
|
+
}
|
124
|
+
|
125
|
+
const profile = await oauthController.userInfo(token);
|
126
|
+
|
127
|
+
res.json(profile);
|
88
128
|
} catch (err) {
|
89
|
-
|
129
|
+
const { message, statusCode = 500 } = err;
|
130
|
+
|
131
|
+
res.status(statusCode).json({ message });
|
90
132
|
}
|
91
133
|
});
|
92
134
|
|
93
135
|
// set the router
|
94
|
-
app.
|
136
|
+
app.use('/sso', router);
|
95
137
|
|
96
138
|
```
|
97
|
-
You can also refer to our usage of the library internally in the Jackson service here - https://github.com/boxyhq/jackson/blob/main/src/jackson.js
|
98
139
|
|
99
|
-
|
100
|
-
|
140
|
+
## Deployment as a service: Docker
|
141
|
+
|
142
|
+
The docker container can be found at [boxyhq/jackson](https://hub.docker.com/r/boxyhq/jackson/tags). It is preferable to use a specific version instead of the `latest` tag. Jackson uses two ports (configurable if needed, see below) 5000 and 6000. 6000 is the internal port and ideally should not be exposed to a public network.
|
101
143
|
|
102
|
-
Example of a docker run:
|
103
144
|
```
|
104
145
|
docker run -p 5000:5000 -p 6000:6000 boxyhq/jackson:78e9099d
|
105
146
|
```
|
106
147
|
|
107
|
-
#
|
108
|
-
Jackson currently supports SQL databases (Postgres, CockroachDB, MySQL and MariaDB), MongoDB and Redis.
|
109
|
-
|
110
|
-
# Configuration
|
111
|
-
Configuration is done via env vars (and in the case of the npm library via an options object). The following options are supported and will have to be configured during deployment:
|
112
|
-
- HOST_URL: The URL to bind to, defaults to `localhost`
|
113
|
-
- HOST_PORT: The port to bind to, defaults to `5000`
|
114
|
-
- EXTERNAL_URL (npm: externalUrl): The public URL to reach this service, used internally for documenting the SAML configuration instructions. Defaults to `http://{HOST_URL}:{HOST_PORT}` for Jackson service, required for npm library
|
115
|
-
- INTERNAL_HOST_URL: The URL to bind to expose the internal APIs, defaults to `localhost`. Do not configure this to a public network
|
116
|
-
- INTERNAL_HOST_PORT: The port to bind to for the internal APIs, defaults to `6000`
|
117
|
-
- SAML_AUDIENCE (npm: samlAudience): This is just an identitifer to validate the SAML audience, this value will also get configured in the SAML apps created by your customers. Once set do not change this value unless you get your customers to reconfigure their SAML again. Defaults to `https://saml.boxyhq.com` and is case sensitive. This does not have be a real URL
|
118
|
-
- IDP_ENABLED (npm: idpEnabled): Set to `true` to enable IdP initiated login for SAML. SP initiated login is the only recommended flow but you might have to support IdP login at times. Defaults to `false`
|
119
|
-
- DB_ENGINE (npm: db.engine): Supported values are `redis`, `sql`, `mongo`, `mem`. Defaults to `sql`
|
120
|
-
- DB_URL (npm: db.url): The database URL to connect to, for example `postgres://postgres:postgres@localhost:5450/jackson`
|
121
|
-
- DB_TYPE (npm: db.type): Only needed when DB_ENGINE is `sql`. Supported values are `postgres`, `cockroachdb`, `mysql`, `mariadb`. Defaults to `postgres`
|
122
|
-
- PRE_LOADED_CONFIG: If you only need a single tenant or a handful of pre-configured tenants then this config will help you read and load SAML configs. It works well with the mem DB engine so you don't have to configure any external databases for this to work (though it works with those as well). This is a path (absolute or relative) to a directory that contains files organized in the format described in the next section.
|
123
|
-
|
124
|
-
# Pre-loaded SAML Configuration
|
125
|
-
If PRE_LOADED_CONFIG is set then it should point to a directory with the following structure (example below):-
|
126
|
-
```
|
127
|
-
boxyhq.js
|
128
|
-
boxyhq.xml
|
129
|
-
anothertenant.js
|
130
|
-
anothertenant.xml
|
131
|
-
```
|
132
|
-
The JS file has the following structure:-
|
133
|
-
```
|
134
|
-
module.exports = {
|
135
|
-
defaultRedirectUrl: 'http://localhost:3000/login/saml',
|
136
|
-
redirectUrl: '["http://localhost:3000/*", "http://localhost:5000/*"]',
|
137
|
-
tenant: 'boxyhq.com',
|
138
|
-
product: 'demo',
|
139
|
-
};
|
140
|
-
```
|
141
|
-
The XML file (should share the name with the .js file) is the raw XML metadata file you receive from your Identity Provider. Please ensure it is saved in the `utf-8` encoding.
|
148
|
+
Refer to https://github.com/boxyhq/jackson#configuration for the full configuration.
|
142
149
|
|
143
|
-
|
150
|
+
Kubernetes and docker-compose deployment files will be coming soon.
|
144
151
|
|
145
|
-
|
146
|
-
|
152
|
+
## Usage
|
153
|
+
|
154
|
+
### 1. Setting up SAML with your customer's Identity Provider
|
155
|
+
|
156
|
+
Please follow the instructions [here](https://docs.google.com/document/d/1fk---Z9Ln59u-2toGKUkyO3BF6Dh3dscT2u4J2xHANE) to guide your customers in setting up SAML correctly for your product(s). You should create a copy of the doc and modify it with your custom settings, we have used the values that work for our demo apps.
|
157
|
+
|
158
|
+
### 1.1 SAML profile/claims/attributes mapping
|
159
|
+
|
160
|
+
As outlined in the guide above we try and support 4 attributes in the SAML claims - `id`, `email`, `firstName`, `lastName`. This is how the common SAML attributes map over for most providers, but some providers have custom mappings. Please refer to the documentation on Identity Provider to understand the exact mapping.
|
161
|
+
|
162
|
+
| SAML Attribute | Jackson mapping |
|
163
|
+
| -------------------------------------------------------------------- | --------------- |
|
164
|
+
| http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier | id |
|
165
|
+
| http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress | email |
|
166
|
+
| http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname | firstName |
|
167
|
+
| http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname | lastName |
|
147
168
|
|
148
|
-
|
149
|
-
Please follow the instructions here to guide your customer's in setting up SAML correctly for your product(s). You should create a copy of the doc and modify it with your custom settings, we have used the values that work for our demo apps - https://docs.google.com/document/d/1fk---Z9Ln59u-2toGKUkyO3BF6Dh3dscT2u4J2xHANE.
|
169
|
+
### 2. SAML config API
|
150
170
|
|
151
|
-
|
152
|
-
Once your customer has set up the SAML app on their Identity Provider, the Identity Provider will generate an IdP or SP metadata file. Some Identity Providers only generate an IdP metadata file but it usually works for the SP login flow as well. It is an XML file that contains various attributes Jackson needs in order to validate incoming SAML login requests. This step is the equivalent of setting an OAuth 2.0 app and generating a client ID and client secret that will be used in the login flow.
|
171
|
+
Once your customer has set up the SAML app on their Identity Provider, the Identity Provider will generate an IdP or SP metadata file. Some Identity Providers only generate an IdP metadata file but it usually works for the SP login flow as well. It is an XML file that contains various attributes Jackson needs to validate incoming SAML login requests. This step is the equivalent of setting an OAuth 2.0 app and generating a client ID and client secret that will be used in the login flow.
|
153
172
|
|
154
173
|
You will need to provide a place in the UI for your customers (The account settings page is usually a good place for this) to configure this and then call the API below.
|
155
174
|
|
156
175
|
The following API call sets up the configuration in Jackson:
|
176
|
+
|
157
177
|
```
|
158
178
|
curl --location --request POST 'http://localhost:6000/api/v1/saml/config' \
|
179
|
+
--header 'Authorization: Api-Key <Jackson API Key>' \
|
159
180
|
--header 'Content-Type: application/x-www-form-urlencoded' \
|
160
181
|
--data-urlencode 'rawMetadata=<IdP/SP metadata XML>' \
|
161
182
|
--data-urlencode 'defaultRedirectUrl=http://localhost:3000/login/saml' \
|
@@ -167,19 +188,44 @@ curl --location --request POST 'http://localhost:6000/api/v1/saml/config' \
|
|
167
188
|
- rawMetadata: The XML metadata file your customer gets from their Identity Provider
|
168
189
|
- defaultRedirectUrl: The redirect URL to use in the IdP login flow. Jackson will call this URL after completing an IdP login flow
|
169
190
|
- redirectUrl: JSON encoded array containing a list of allowed redirect URLs. Jackson will disallow any redirects not on this list (or not the default URL above)
|
170
|
-
- tenant: Jackson supports a multi-tenant architecture, this is a unique identifier you set from your side that relates back to your customer's tenant. This is normally an email, domain, an account id, or user
|
191
|
+
- tenant: Jackson supports a multi-tenant architecture, this is a unique identifier you set from your side that relates back to your customer's tenant. This is normally an email, domain, an account id, or user-id
|
171
192
|
- product: Jackson support multiple products, this is a unique identifier you set from your side that relates back to the product your customer is using
|
172
193
|
|
173
|
-
The response returns a JSON with `client_id` and `client_secret` that can be stored against your tenant and product for a more secure OAuth 2.0 flow. If you do not want to store the `client_id` and `client_secret` you can alternatively use `client_id=
|
194
|
+
The response returns a JSON with `client_id` and `client_secret` that can be stored against your tenant and product for a more secure OAuth 2.0 flow. If you do not want to store the `client_id` and `client_secret` you can alternatively use `client_id=tenant=<tenantID>&product=<productID>` and any arbitrary value for `client_secret` when setting up the OAuth 2.0 flow. Additionally a `provider` attribute is also returned which indicates the domain of your Identity Provider.
|
195
|
+
|
196
|
+
#### 2.1 SAML get config API
|
197
|
+
|
198
|
+
This endpoint can be used to return metadata about an existing SAML config. This can be used to check and display the details to your customers. You can use either `clientID` or `tenant` and `product` combination.
|
199
|
+
|
200
|
+
```
|
201
|
+
curl --location --request POST 'http://localhost:6000/api/v1/saml/config/get' \
|
202
|
+
--header 'Authorization: Api-Key <Jackson API Key>' \
|
203
|
+
--header 'Content-Type: application/x-www-form-urlencoded' \
|
204
|
+
--data-urlencode 'tenant=boxyhq.com' \
|
205
|
+
--data-urlencode 'product=demo'
|
206
|
+
```
|
207
|
+
|
208
|
+
```
|
209
|
+
curl --location --request POST 'http://localhost:6000/api/v1/saml/config/get' \
|
210
|
+
--header 'Authorization: Api-Key <Jackson API Key>' \
|
211
|
+
--header 'Content-Type: application/x-www-form-urlencoded' \
|
212
|
+
--data-urlencode 'clientID=<Client ID>'
|
213
|
+
```
|
214
|
+
|
215
|
+
The response returns a JSON with `provider` indicating the domain of your Identity Provider. If an empty JSON payload is returned then we do not have any configuration stored for the attributes you requested.
|
216
|
+
|
217
|
+
### 3. OAuth 2.0 Flow
|
174
218
|
|
175
|
-
# OAuth 2.0 Flow
|
176
219
|
Jackson has been designed to abstract the SAML login flow as a pure OAuth 2.0 flow. This means it's compatible with any standard OAuth 2.0 library out there, both client-side and server-side. It is important to remember that SAML is configured per customer unlike OAuth 2.0 where you can have a single OAuth app supporting logins for all customers.
|
177
220
|
|
178
221
|
Jackson also supports the PKCE authorization flow (https://oauth.net/2/pkce/), so you can protect your SPAs.
|
179
222
|
|
180
223
|
If for any reason you need to implement the flow on your own, the steps are outlined below:
|
181
|
-
|
224
|
+
|
225
|
+
### 4. Authorize
|
226
|
+
|
182
227
|
The OAuth flow begins with redirecting your user to the `authorize` URL:
|
228
|
+
|
183
229
|
```
|
184
230
|
https://localhost:5000/oauth/authorize
|
185
231
|
?response_type=code&provider=saml
|
@@ -189,30 +235,34 @@ https://localhost:5000/oauth/authorize
|
|
189
235
|
```
|
190
236
|
|
191
237
|
- response_type=code: This is the only supported type for now but maybe extended in the future
|
192
|
-
- client_id: Use the client_id returned by the SAML config API or use `
|
238
|
+
- client_id: Use the client_id returned by the SAML config API or use `tenant=<tenantID>&product=<productID>` to use the tenant and product IDs instead. **Note:** Please don't forget to URL encode the query parameters including `client_id`.
|
193
239
|
- redirect_uri: This is where the user will be taken back once the authorization flow is complete
|
194
240
|
- state: Use a randomly generated string as the state, this will be echoed back as a query parameter when taking the user back to the `redirect_uri` above. You should validate the state to prevent XSRF attacks
|
195
241
|
|
196
|
-
|
197
|
-
|
242
|
+
### 5. Code Exchange
|
243
|
+
|
244
|
+
After successful authorization, the user is redirected back to the `redirect_uri`. The query parameters will include the `code` and `state` parameters. You should validate that the state matches the one you sent in the `authorize` request.
|
198
245
|
|
199
246
|
The code can then be exchanged for a token by making the following request:
|
247
|
+
|
200
248
|
```
|
201
249
|
curl --request POST \
|
202
250
|
--url 'http://localhost:5000/oauth/token' \
|
203
251
|
--header 'content-type: application/x-www-form-urlencoded' \
|
204
|
-
--data grant_type=authorization_code \
|
252
|
+
--data 'grant_type=authorization_code' \
|
205
253
|
--data 'client_id=<clientID or tenant and product query params as described in the SAML config API section above>' \
|
206
|
-
--data client_secret=<clientSecret or any arbitrary value if using the tenant and product in the clientID> \
|
254
|
+
--data 'client_secret=<clientSecret or any arbitrary value if using the tenant and product in the clientID>' \
|
207
255
|
--data 'redirect_uri=<redirect URL>' \
|
208
|
-
--data code=<code from the query parameter above>
|
256
|
+
--data 'code=<code from the query parameter above>'
|
209
257
|
```
|
258
|
+
|
210
259
|
- grant_type=authorization_code: This is the only supported flow, for now. We might extend this in the future
|
211
|
-
- client_id: Use the client_id returned by the SAML config API or use `
|
260
|
+
- client_id: Use the client_id returned by the SAML config API or use `tenant=<tenantID>&product=<productID>` to use the tenant and product IDs instead. **Note:** Please don't forget to URL encode the query parameters including `client_id`.
|
212
261
|
- client_secret: Use the client_secret returned by the SAML config API or any arbitrary value if using the tenant and product in the clientID
|
213
262
|
- redirect_uri: This is where the user will be taken back once the authorization flow is complete. Use the same redirect_uri as the previous request
|
214
263
|
|
215
264
|
If everything goes well you should receive a JSON response that includes the access token. This token is needed for the next step where we fetch the user profile.
|
265
|
+
|
216
266
|
```
|
217
267
|
{
|
218
268
|
"access_token": <access token>,
|
@@ -221,8 +271,10 @@ If everything goes well you should receive a JSON response that includes the acc
|
|
221
271
|
}
|
222
272
|
```
|
223
273
|
|
224
|
-
|
274
|
+
### 6. Profile Request
|
275
|
+
|
225
276
|
The short-lived access token can now be used to request the user's profile. You'll need to make the following request:
|
277
|
+
|
226
278
|
```
|
227
279
|
curl --request GET \
|
228
280
|
--url https://localhost:5000/oauth/me \
|
@@ -231,16 +283,106 @@ curl --request GET \
|
|
231
283
|
```
|
232
284
|
|
233
285
|
If everything goes well you should receive a JSON response with the user's profile:
|
286
|
+
|
234
287
|
```
|
235
288
|
{
|
289
|
+
"id": <id from the Identity Provider>,
|
236
290
|
"email": "sjackson@coolstartup.com",
|
237
291
|
"firstName": "SAML"
|
238
|
-
"
|
239
|
-
"lastName": "Jackson",
|
292
|
+
"lastName": "Jackson"
|
240
293
|
}
|
241
294
|
```
|
242
295
|
|
243
|
-
- email: The email address of the user as provided by the Identity Provider
|
244
296
|
- id: The id of the user as provided by the Identity Provider
|
297
|
+
- email: The email address of the user as provided by the Identity Provider
|
245
298
|
- firstName: The first name of the user as provided by the Identity Provider
|
246
299
|
- lastName: The last name of the user as provided by the Identity Provider
|
300
|
+
|
301
|
+
## Examples
|
302
|
+
|
303
|
+
To Do
|
304
|
+
|
305
|
+
## Database Support
|
306
|
+
|
307
|
+
Jackson currently supports the following databases.
|
308
|
+
|
309
|
+
- Postgres
|
310
|
+
- CockroachDB
|
311
|
+
- MySQL
|
312
|
+
- MariaDB
|
313
|
+
- MongoDB
|
314
|
+
- Redis
|
315
|
+
|
316
|
+
## Configuration
|
317
|
+
|
318
|
+
Configuration is done via env vars (and in the case of the npm library via an options object).
|
319
|
+
|
320
|
+
The following options are supported and will have to be configured during deployment.
|
321
|
+
|
322
|
+
| Key | Description | Default |
|
323
|
+
| --------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------- |
|
324
|
+
| HOST_URL | The URL to bind to | `localhost` |
|
325
|
+
| HOST_PORT | The port to bind to | `5000` |
|
326
|
+
| EXTERNAL_URL (npm: externalUrl) | The public URL to reach this service, used internally for documenting the SAML configuration instructions. | `http://{HOST_URL}:{HOST_PORT}` |
|
327
|
+
| INTERNAL_HOST_URL | The URL to bind to expose the internal APIs. Do not configure this to a public network. | `localhost` |
|
328
|
+
| INTERNAL_HOST_PORT | The port to bind to for the internal APIs. | `6000` |
|
329
|
+
| JACKSON_API_KEYS | A comma separated list of API keys that will be validated when serving the Config API requests | |
|
330
|
+
| SAML_AUDIENCE (npm: samlAudience) | This is just an identifier to validate the SAML audience, this value will also get configured in the SAML apps created by your customers. Once set do not change this value unless you get your customers to reconfigure their SAML again. It is case-sensitive. This does not have to be a real URL. | `https://saml.boxyhq.com` |
|
331
|
+
| IDP_ENABLED (npm: idpEnabled) | Set to `true` to enable IdP initiated login for SAML. SP initiated login is the only recommended flow but you might have to support IdP login at times. | `false` |
|
332
|
+
| DB_ENGINE (npm: db.engine) | Supported values are `redis`, `sql`, `mongo`, `mem`. | `sql` |
|
333
|
+
| DB_URL (npm: db.url) | The database URL to connect to. For example `postgres://postgres:postgres@localhost:5450/jackson` | |
|
334
|
+
| DB_TYPE (npm: db.type) | Only needed when DB_ENGINE is `sql`. Supported values are `postgres`, `cockroachdb`, `mysql`, `mariadb`. | `postgres` |
|
335
|
+
| PRE_LOADED_CONFIG | If you only need a single tenant or a handful of pre-configured tenants then this config will help you read and load SAML configs. It works well with the mem DB engine so you don't have to configure any external databases for this to work (though it works with those as well). This is a path (absolute or relative) to a directory that contains files organized in the format described in the next section. | |
|
336
|
+
|
337
|
+
## Pre-loaded SAML Configuration
|
338
|
+
|
339
|
+
If PRE_LOADED_CONFIG is set then it should point to a directory with the following structure (example below):-
|
340
|
+
|
341
|
+
```
|
342
|
+
boxyhq.js
|
343
|
+
boxyhq.xml
|
344
|
+
anothertenant.js
|
345
|
+
anothertenant.xml
|
346
|
+
```
|
347
|
+
|
348
|
+
The JS file has the following structure:-
|
349
|
+
|
350
|
+
```
|
351
|
+
module.exports = {
|
352
|
+
defaultRedirectUrl: 'http://localhost:3000/login/saml',
|
353
|
+
redirectUrl: '["http://localhost:3000/*", "http://localhost:5000/*"]',
|
354
|
+
tenant: 'boxyhq.com',
|
355
|
+
product: 'demo',
|
356
|
+
};
|
357
|
+
```
|
358
|
+
|
359
|
+
The XML file (should share the name with the .js file) is the raw XML metadata file you receive from your Identity Provider. Please ensure it is saved in the `utf-8` encoding.
|
360
|
+
|
361
|
+
The config and XML above correspond to the `SAML API config` (see below).
|
362
|
+
|
363
|
+
## SAML Login flows
|
364
|
+
|
365
|
+
There are two kinds of SAML login flows - SP-initiated and IdP-initiated. We highly recommend sticking to the SP-initiated flow since it is more secure but Jackson also supports the IdP-initiated flow if you enable it. For an in-depth understanding of SAML and the two flows please refer to Okta's comprehensive guide - https://developer.okta.com/docs/concepts/saml/.
|
366
|
+
|
367
|
+
## Contributing
|
368
|
+
|
369
|
+
Thanks for taking the time to contribute! Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make will benefit everybody else and are appreciated.
|
370
|
+
|
371
|
+
Please try to create bug reports that are:
|
372
|
+
|
373
|
+
- _Reproducible._ Include steps to reproduce the problem.
|
374
|
+
- _Specific._ Include as much detail as possible: which version, what environment, etc.
|
375
|
+
- _Unique._ Do not duplicate existing opened issues.
|
376
|
+
- _Scoped to a Single Bug._ One bug per report.
|
377
|
+
|
378
|
+
## Support
|
379
|
+
|
380
|
+
Reach out to the maintainer at one of the following places:
|
381
|
+
|
382
|
+
- [GitHub Discussions](https://github.com/boxyhq/jackson/discussions)
|
383
|
+
- [GitHub Issues](https://github.com/boxyhq/jackson/issues)
|
384
|
+
- The email which is located [in GitHub profile](https://github.com/deepakprabhakara)
|
385
|
+
|
386
|
+
## License
|
387
|
+
|
388
|
+
[Apache 2.0 License](https://github.com/boxyhq/jackson/blob/main/LICENSE)
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@boxyhq/saml-jackson",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.2.0-beta.149",
|
4
4
|
"license": "Apache 2.0",
|
5
5
|
"description": "SAML 2.0 service",
|
6
6
|
"main": "src/index.js",
|
@@ -17,11 +17,12 @@
|
|
17
17
|
"scripts": {
|
18
18
|
"start": "cross-env IDP_ENABLED=true node src/jackson.js",
|
19
19
|
"dev": "cross-env IDP_ENABLED=true nodemon src/jackson.js",
|
20
|
-
"calendso": "cross-env DB_URL=postgresql://postgres:postgres@localhost:5450/calendso nodemon src/jackson.js",
|
21
20
|
"mongo": "cross-env DB_ENGINE=mongo DB_URL=mongodb://localhost:27017/jackson nodemon src/jackson.js",
|
22
21
|
"pre-loaded": "cross-env DB_ENGINE=mem PRE_LOADED_CONFIG='./_config' nodemon src/jackson.js",
|
22
|
+
"pre-loaded-db": "cross-env PRE_LOADED_CONFIG='./_config' nodemon src/jackson.js",
|
23
23
|
"test": "tap --timeout=100 src/**/*.test.js",
|
24
|
-
"dev-dbs": "docker-compose -f ./_dev/docker-compose.yml up -d"
|
24
|
+
"dev-dbs": "docker-compose -f ./_dev/docker-compose.yml up -d",
|
25
|
+
"dev-dbs-destroy": "docker-compose -f ./_dev/docker-compose.yml down --volumes --remove-orphans"
|
25
26
|
},
|
26
27
|
"tap": {
|
27
28
|
"coverage-map": "map.js",
|
@@ -32,27 +33,35 @@
|
|
32
33
|
},
|
33
34
|
"dependencies": {
|
34
35
|
"@boxyhq/saml20": "0.2.0",
|
35
|
-
"@peculiar/webcrypto": "1.
|
36
|
-
"@peculiar/x509": "1.
|
36
|
+
"@peculiar/webcrypto": "1.2.2",
|
37
|
+
"@peculiar/x509": "1.6.0",
|
37
38
|
"cors": "2.8.5",
|
38
39
|
"express": "4.17.1",
|
39
|
-
"mongodb": "4.1
|
40
|
-
"mysql2": "
|
40
|
+
"mongodb": "4.2.1",
|
41
|
+
"mysql2": "2.3.3",
|
41
42
|
"pg": "8.7.1",
|
42
43
|
"rambda": "6.9.0",
|
43
|
-
"redis": "4.0.0-rc.
|
44
|
+
"redis": "4.0.0-rc.4",
|
44
45
|
"reflect-metadata": "0.1.13",
|
45
46
|
"ripemd160": "2.0.2",
|
46
47
|
"thumbprint": "0.0.1",
|
47
|
-
"typeorm": "0.2.
|
48
|
+
"typeorm": "0.2.41",
|
48
49
|
"xml-crypto": "2.1.3",
|
49
50
|
"xml2js": "0.4.23",
|
50
51
|
"xmlbuilder": "15.1.1"
|
51
52
|
},
|
52
53
|
"devDependencies": {
|
53
54
|
"cross-env": "7.0.3",
|
54
|
-
"eslint": "
|
55
|
-
"
|
56
|
-
"
|
55
|
+
"eslint": "8.4.0",
|
56
|
+
"husky": "7.0.4",
|
57
|
+
"lint-staged": "12.1.2",
|
58
|
+
"nodemon": "2.0.15",
|
59
|
+
"prettier": "2.5.1",
|
60
|
+
"sinon": "12.0.1",
|
61
|
+
"tap": "15.1.5"
|
62
|
+
},
|
63
|
+
"lint-staged": {
|
64
|
+
"*.js": "eslint --cache --fix",
|
65
|
+
"*.{js,css,md}": "prettier --write"
|
57
66
|
}
|
58
67
|
}
|