Skip to content

Instantly share code, notes, and snippets.

@nriesco
Created March 13, 2020 13:15
Show Gist options
  • Save nriesco/7b821678ca8c404367caf7a6b3165f42 to your computer and use it in GitHub Desktop.
Save nriesco/7b821678ca8c404367caf7a6b3165f42 to your computer and use it in GitHub Desktop.
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