@boxyhq/saml-jackson 0.1.5-beta.118 → 0.1.5-beta.123
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/README.md +13 -3
- package/package.json +1 -1
- package/src/controller/oauth.js +0 -5
- package/src/saml/claims.js +40 -0
- package/src/saml/saml.js +14 -0
package/README.md
CHANGED
@@ -128,6 +128,16 @@ Kubernetes and docker-compose deployment files will be coming soon.
|
|
128
128
|
|
129
129
|
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.
|
130
130
|
|
131
|
+
### 1.1 SAML profile/claims/attributes mapping
|
132
|
+
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 aattributes map over for most providers, but some providers have custom mappings. Please refer to the documentation on Identity Provider to understand the exact mapping.
|
133
|
+
|
134
|
+
| SAML Attribute | Jackson mapping |
|
135
|
+
|----------------|-----------------|
|
136
|
+
|http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier|id|
|
137
|
+
|http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress|email|
|
138
|
+
|http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname|firstName|
|
139
|
+
|http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname|lastName|
|
140
|
+
|
131
141
|
### 2. SAML config API
|
132
142
|
|
133
143
|
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.
|
@@ -152,7 +162,7 @@ curl --location --request POST 'http://localhost:6000/api/v1/saml/config' \
|
|
152
162
|
- 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
|
153
163
|
- 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
|
154
164
|
|
155
|
-
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=
|
165
|
+
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.
|
156
166
|
|
157
167
|
### 3. OAuth 2.0 Flow
|
158
168
|
|
@@ -175,7 +185,7 @@ https://localhost:5000/oauth/authorize
|
|
175
185
|
```
|
176
186
|
|
177
187
|
- response_type=code: This is the only supported type for now but maybe extended in the future
|
178
|
-
- client_id: Use the client_id returned by the SAML config API or use `
|
188
|
+
- 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`.
|
179
189
|
- redirect_uri: This is where the user will be taken back once the authorization flow is complete
|
180
190
|
- 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
|
181
191
|
|
@@ -197,7 +207,7 @@ curl --request POST \
|
|
197
207
|
```
|
198
208
|
|
199
209
|
- grant_type=authorization_code: This is the only supported flow, for now. We might extend this in the future
|
200
|
-
- client_id: Use the client_id returned by the SAML config API or use `
|
210
|
+
- 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`.
|
201
211
|
- 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
|
202
212
|
- 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
|
203
213
|
|
package/package.json
CHANGED
package/src/controller/oauth.js
CHANGED
@@ -186,11 +186,6 @@ const samlResponse = async (req, res) => {
|
|
186
186
|
}
|
187
187
|
|
188
188
|
const profile = await saml.validateAsync(rawResponse, validateOpts);
|
189
|
-
|
190
|
-
// some providers don't return the id in the assertion, we set it to a sha256 hash of the email
|
191
|
-
if (profile && profile.claims && !profile.claims.id) {
|
192
|
-
profile.claims.id = crypto.createHash('sha256').update(profile.claims.email).digest('hex');
|
193
|
-
}
|
194
189
|
|
195
190
|
// store details against a code
|
196
191
|
const code = crypto.randomBytes(20).toString('hex');
|
@@ -0,0 +1,40 @@
|
|
1
|
+
const mapping = [
|
2
|
+
{
|
3
|
+
attribute: 'id',
|
4
|
+
schema:
|
5
|
+
'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier',
|
6
|
+
},
|
7
|
+
{
|
8
|
+
attribute: 'email',
|
9
|
+
schema:
|
10
|
+
'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress',
|
11
|
+
},
|
12
|
+
{
|
13
|
+
attribute: 'firstName',
|
14
|
+
schema: 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname',
|
15
|
+
},
|
16
|
+
{
|
17
|
+
attribute: 'lastName',
|
18
|
+
schema: 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname',
|
19
|
+
},
|
20
|
+
];
|
21
|
+
|
22
|
+
const map = (claims) => {
|
23
|
+
const profile = {
|
24
|
+
raw: claims,
|
25
|
+
};
|
26
|
+
|
27
|
+
mapping.forEach((m) => {
|
28
|
+
if (claims[m.attribute]) {
|
29
|
+
profile[m.attribute] = claims[m.attribute];
|
30
|
+
} else if (claims[m.schema]) {
|
31
|
+
profile[m.attribute] = claims[m.schema];
|
32
|
+
}
|
33
|
+
});
|
34
|
+
|
35
|
+
return profile;
|
36
|
+
};
|
37
|
+
|
38
|
+
module.exports = {
|
39
|
+
map,
|
40
|
+
};
|
package/src/saml/saml.js
CHANGED
@@ -5,6 +5,7 @@ const thumbprint = require('thumbprint');
|
|
5
5
|
const xmlbuilder = require('xmlbuilder');
|
6
6
|
const crypto = require('crypto');
|
7
7
|
const xmlcrypto = require('xml-crypto');
|
8
|
+
const claims = require('./claims');
|
8
9
|
|
9
10
|
const idPrefix = '_';
|
10
11
|
const authnXPath =
|
@@ -120,6 +121,19 @@ module.exports = {
|
|
120
121
|
return;
|
121
122
|
}
|
122
123
|
|
124
|
+
if (profile && profile.claims) {
|
125
|
+
// we map claims to our attributes id, email, firstName, lastName where possible. We also map original claims to raw
|
126
|
+
profile.claims = claims.map(profile.claims);
|
127
|
+
|
128
|
+
// some providers don't return the id in the assertion, we set it to a sha256 hash of the email
|
129
|
+
if (!profile.claims.id) {
|
130
|
+
profile.claims.id = crypto
|
131
|
+
.createHash('sha256')
|
132
|
+
.update(profile.claims.email)
|
133
|
+
.digest('hex');
|
134
|
+
}
|
135
|
+
}
|
136
|
+
|
123
137
|
resolve(profile);
|
124
138
|
}
|
125
139
|
);
|