Skip to content

Commit

Permalink
Add avatar_url from Github to Passport's profile.photos
Browse files Browse the repository at this point in the history
  • Loading branch information
skogsmaskin committed Aug 30, 2017
1 parent a456666 commit b274eb4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/profile.js
Expand Up @@ -18,6 +18,8 @@ exports.parse = function(json) {
if (json.email) {
profile.emails = [{ value: json.email }];
}

if (json.avatar_url) {
profile.photos = [{ value: json.avatar_url }];
}
return profile;
};
6 changes: 4 additions & 2 deletions test/strategy.profile.test.js
Expand Up @@ -15,8 +15,8 @@ describe('Strategy#userProfile', function() {
// mock
strategy._oauth2.get = function(url, accessToken, callback) {
var testcases = {
'https://api.github.com/user': '{ "login": "octocat", "id": 1, "name": "monalisa octocat", "email": "octocat@github.com", "html_url": "https://github.com/octocat" }',
'https://api.github.com/user/emails': '[ { "email": "octocat@github.com", "verified": true, "primary": true } ]'
'https://api.github.com/user': '{ "login": "octocat", "id": 1, "name": "monalisa octocat", "email": "octocat@github.com", "avatar_url": "https://avatars1.githubusercontent.com/u/583231?v=3&s=460", "html_url": "https://github.com/octocat" }',
'https://api.github.com/user/emails': '[ { "email": "octocat@github.com", "verified": true, "primary": true } ]'
};

var body = testcases[url] || null;
Expand Down Expand Up @@ -48,6 +48,8 @@ describe('Strategy#userProfile', function() {
expect(profile.profileUrl).to.equal('https://github.com/octocat');
expect(profile.emails).to.have.length(1);
expect(profile.emails[0].value).to.equal('octocat@github.com');
expect(profile.photos).to.have.length(1);
expect(profile.photos[0].value).to.equal('https://avatars1.githubusercontent.com/u/583231?v=3&s=460');
});

it('should set raw property', function() {
Expand Down

0 comments on commit b274eb4

Please sign in to comment.