Created
March 13, 2020 13:15
-
-
Save nriesco/7b821678ca8c404367caf7a6b3165f42 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class GitHubStrategy extends OAuthStrategy { | |
async getProfile (authResult) { | |
const accessToken = authResult.access_token; | |
// get private email | |
let { data } = await axios.get('https://api.github.com/user/emails', { | |
headers: { authorization: `Bearer ${accessToken}` } | |
}); | |
// get user data | |
let userData = await axios.get('https://api.github.com/user', { | |
headers: { authorization: `Bearer ${accessToken}` } | |
}); | |
try { | |
data = data[0]; | |
// add relevant user data | |
data.avatar_url = userData.data.avatar_url | |
data.name = userData.data.name | |
return data | |
} catch (e) {} | |
} | |
async getEntityData(profile) { | |
const baseData = await super.getEntityData(profile); | |
// don't get the email from the profile | |
const data = { | |
...baseData, | |
// email: profile.email | |
}; | |
// your logic goes here! | |
return data; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment