@boxyhq/saml-jackson 0.1.5-beta.119 → 0.1.5-beta.124

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 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.
@@ -189,11 +199,11 @@ The code can then be exchanged for a token by making the following request:
189
199
  curl --request POST \
190
200
  --url 'http://localhost:5000/oauth/token' \
191
201
  --header 'content-type: application/x-www-form-urlencoded' \
192
- --data grant_type=authorization_code \
202
+ --data 'grant_type=authorization_code' \
193
203
  --data 'client_id=<clientID or tenant and product query params as described in the SAML config API section above>' \
194
- --data client_secret=<clientSecret or any arbitrary value if using the tenant and product in the clientID> \
204
+ --data 'client_secret=<clientSecret or any arbitrary value if using the tenant and product in the clientID>' \
195
205
  --data 'redirect_uri=<redirect URL>' \
196
- --data code=<code from the query parameter above>
206
+ --data 'code=<code from the query parameter above>'
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
@@ -226,15 +236,15 @@ If everything goes well you should receive a JSON response with the user's profi
226
236
 
227
237
  ```
228
238
  {
239
+ "id": <id from the Identity Provider>,
229
240
  "email": "sjackson@coolstartup.com",
230
241
  "firstName": "SAML"
231
- "id": <id from the Identity Provider>,
232
- "lastName": "Jackson",
242
+ "lastName": "Jackson"
233
243
  }
234
244
  ```
235
245
 
236
- - email: The email address of the user as provided by the Identity Provider
237
246
  - id: The id of the user as provided by the Identity Provider
247
+ - email: The email address of the user as provided by the Identity Provider
238
248
  - firstName: The first name of the user as provided by the Identity Provider
239
249
  - lastName: The last name of the user as provided by the Identity Provider
240
250
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boxyhq/saml-jackson",
3
- "version": "0.1.5-beta.119",
3
+ "version": "0.1.5-beta.124",
4
4
  "license": "Apache 2.0",
5
5
  "description": "SAML 2.0 service",
6
6
  "main": "src/index.js",
@@ -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
  );