Created
May 12, 2023 21:49
-
-
Save WietseWind/1954f31aff8fbc8096c6734d616867aa to your computer and use it in GitHub Desktop.
Auth0 fetch user profile script
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 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