Skip to content

Instantly share code, notes, and snippets.

@saltukalakus
Last active June 5, 2021 08:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saltukalakus/5e5c8986d9a4f3660fc65f4bfef16e0b to your computer and use it in GitHub Desktop.
Save saltukalakus/5e5c8986d9a4f3660fc65f4bfef16e0b to your computer and use it in GitHub Desktop.
Auth0 SAML IdP mapping attributes from within arrays
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);
}
{
"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