Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function (user, context, callback) {
if (context.clientID === '{{auth0-application-client-id}}') {
const RULE_NAME = 'talentlms-samlmappings';
const CLIENTNAME = context.clientName;
console.log(`${RULE_NAME} started by ${CLIENTNAME}`);
if (!user.user_metadata.given_name || _.isEmpty(user.user_metadata.given_name) ||
!user.user_metadata.family_name || _.isEmpty(user.user_metadata.family_name))
{
console.log(`${RULE_NAME} Insuffient user_metadata for TalentLMS - given_name: ${user.user_metadata.given_name} family_name: ${user.user_metadata.family_name}`);
callback(null, user, context);
}
var auth0Identity = _.find(user.identities, function(u) { return u.provider === 'auth0'; });
var alphanumericUserId = auth0Identity.provider + auth0Identity.user_id;
user.app_metadata = user.app_metadata || {};
user.app_metadata.alphanumeric_auth0_user_id = alphanumericUserId;
context.samlConfiguration.mappings = {
"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier": "app_metadata.alphanumeric_auth0_user_id",
"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress": "email",
"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/given_name": "user_metadata.given_name",
"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/family_name": "user_metadata.family_name"
};
}
callback(null, user, context);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment