Last active
June 5, 2021 08:11
-
-
Save saltukalakus/5e5c8986d9a4f3660fc65f4bfef16e0b to your computer and use it in GitHub Desktop.
Auth0 SAML IdP mapping attributes from within arrays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function (user, context, callback) { | |
// App's client ID | |
var samlIdpClientId = 'QnlrTOQdFxxRYYZVS27Dcko5uu5fenaW'; | |
if (context.clientID !== samlIdpClientId) { | |
return callback(null, user, context); | |
} | |
const addresses = user.addresses && user.addresses[0] || {}; | |
user.tmpCity = addresses.locality; | |
user.tmpState = addresses.region; | |
user.tmpCountry = addresses.country; | |
user.tmpRoles = context.authorization.roles; | |
context.samlConfiguration.mappings = { | |
"mail": "email", | |
"nameID": "email", | |
"givenName": "given_name", | |
"sn": "family_name", | |
"city": "tmpCity", | |
"state": "tmpState", | |
"country" : "tmpCountry", | |
"roles" : "tmpRoles" | |
}; | |
callback(null, user, context); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"id": "118028435727952686478", | |
"primaryEmail": "john@dough.com", | |
"name": "John Dough", | |
"isAdmin": false, | |
"isDelegatedAdmin": false, | |
"lastLoginTime": "2021-01-05T13:27:25.000Z", | |
"creationTime": "2016-10-03T15:55:40.000Z", | |
"addresses": [ | |
{ | |
"locality": "İzmir", | |
"region": "NA", | |
"country": "Turkey" | |
} | |
], | |
"user_id": "google-apps|john@dough.com", | |
"identities": [ | |
{ | |
"provider": "google-apps", | |
"user_id": "john@dough.com", | |
"connection": "acme", | |
"isSocial": false | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment