Social Identity Retrieval Code

Hi, would like to donate my code which migrated social identity retrieval from Rules to Actions and so far appears to have worked:

exports.onExecutePostLogin = async (event, api) => {
  if(event.connection.strategy!=='twitter'&&event.connection.strategy!=='linkedin')return;
  let _=require('lodash');
  const ManagementClient = require('auth0').ManagementClient;
  const management = new ManagementClient({
    domain:'<domain>',
    clientId:'<Machine to Machine clientId>',
    clientSecret:'<Machine to Machine secret>'
  });

  let socialIdentity=null;
  try {
    let user = await management.users.get({ id: event.user.user_id });
    socialIdentity = _.find(user.data.identities,identity=>identity.connection===event.connection.strategy);
    if(!socialIdentity)throw new Error(JSON.stringify(user));
  } catch (error) {
    console.error('Error fetching social identity', error);
    return;
  }
  api.idToken.setCustomClaim('http://<domain>/socialIdentity',socialIdentity);
};

Hi @customautosys

Welcome to the Auth0 Community!

Thank you for this donation and for being a valuable community member!

Dawid

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.