Skip to content

Instantly share code, notes, and snippets.

@WietseWind
Created May 12, 2023 21:49
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 WietseWind/1954f31aff8fbc8096c6734d616867aa to your computer and use it in GitHub Desktop.
Save WietseWind/1954f31aff8fbc8096c6734d616867aa to your computer and use it in GitHub Desktop.
Auth0 fetch user profile script
function fetchUserProfile(accessToken, context, callback) {
request.get(
{
url: 'https://oauth2.xumm.app/userinfo',
headers: {
'Authorization': 'Bearer ' + accessToken,
}
},
(err, resp, body) => {
if (err) {
return callback(err);
}
if (resp.statusCode !== 200) {
return callback(new Error(body));
}
let bodyParsed;
try {
bodyParsed = JSON.parse(body);
} catch (jsonError) {
return callback(new Error(body));
}
const profile = {
user_id: bodyParsed.sub,
kycApproved: bodyParsed.kycApproved,
proSubscription: bodyParsed.proSubscription,
picture: bodyParsed.picture,
name: bodyParsed.name
};
callback(null, profile);
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment