-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProfileMapper.js
77 lines (66 loc) · 2.13 KB
/
ProfileMapper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//shorthands claims namespaces
var fm = {
'nameIdentifier': 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier',
'givenname': 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname',
'surname': 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname',
};
/**
* Claim Types:
* http://msdn.microsoft.com/en-us/library/microsoft.identitymodel.claims.claimtypes_members.aspx
*
* @param {Object} user passed by getUserFromRequest method in app.js
*/
function ProfileMapper (pu) {
if(!(this instanceof ProfileMapper)) {
return new ProfileMapper(pu);
}
this._pu = pu;
}
/**
*
* @return {Object} WsFederation claim identity
*/
ProfileMapper.prototype.getClaims = function () {
var claims = {};
claims[fm.nameIdentifier] = this._pu.email;
claims[fm.givenname] = this._pu.given_name;
claims[fm.surname] = this._pu.family_name;
var dontRemapAttributes = ['emails', 'displayName', 'name', 'id', '_json'];
Object.keys(this._pu).filter(function (k) {
return !~dontRemapAttributes.indexOf(k);
})
return claims;
};
/**
* returns the nameidentifier for the saml token.
*
* @return {Object} object containing a nameIdentifier property and optional nameIdentifierFormat.
*/
ProfileMapper.prototype.getNameIdentifier = function () {
var claims = this.getClaims();
return {
nameIdentifier: claims[fm.nameIdentifier]
};
};
/**
* claims metadata used in the metadata endpoint.
*
* @return {[type]} WsFederation claim identity
*/
ProfileMapper.prototype.metadata = [ {
id: "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname",
optional: true,
displayName: 'Given Name',
description: 'The given name of the user'
},{
id: "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname",
optional: true,
displayName: 'Surname',
description: 'The surname of the user'
}, {
id: "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier",
optional: true,
displayName: 'Name ID',
description: 'The SAML name identifier of the user'
}];
module.exports = ProfileMapper;