Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jaredhanson/passport-github
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: zubeio/passport-github
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 1 commit
  • 1 file changed
  • 1 contributor

Commits on Apr 4, 2016

  1. temp logs for debugging

    204NoContent committed Apr 4, 2016
    Copy the full SHA
    cc72482 View commit details
Showing with 19 additions and 10 deletions.
  1. +19 −10 lib/strategy.js
29 changes: 19 additions & 10 deletions lib/strategy.js
Original file line number Diff line number Diff line change
@@ -63,15 +63,19 @@ function Strategy(options, verify) {
this.name = 'github';
this._userProfileURL = options.userProfileURL || 'https://api.github.com/user';
this._oauth2.useAuthorizationHeaderforGET(true);

// NOTE: GitHub returns an HTTP 200 OK on error responses. As a result, the
// underlying `oauth` implementation understandably does not parse the
// response as an error. This code swizzles the implementation to
// handle this condition.
var self = this;
var _oauth2_getOAuthAccessToken = this._oauth2.getOAuthAccessToken;
this._oauth2.getOAuthAccessToken = function(code, params, callback) {
console.log('pre oauth', code);
_oauth2_getOAuthAccessToken.call(self._oauth2, code, params, function(err, accessToken, refreshToken, params) {
console.log('post oauth err', err);
console.log('post oauth code', code);
console.log('post oauth accessToken', accessToken);
if (err) { return callback(err); }
if (!accessToken) {
return callback({
@@ -106,28 +110,33 @@ util.inherits(Strategy, OAuth2Strategy);
*/
Strategy.prototype.userProfile = function(accessToken, done) {
var self = this;
console.log('pre userProfile', this._userProfileURL, accessToken);
this._oauth2.get(this._userProfileURL, accessToken, function (err, body, res) {
var json;


console.log('post userProfile accessToken', accessToken.slice(-8));
console.log('post userProfile err', err);
console.log('post userProfile body', body);

if (err) {
if (err.data) {
try {
json = JSON.parse(err.data);
} catch (_) {}
}

if (json && json.message) {
return done(new APIError(json.message));
}
return done(new InternalOAuthError('Failed to fetch user profile', err));
}

try {
json = JSON.parse(body);
} catch (ex) {
return done(new Error('Failed to parse user profile'));
}

var profile = Profile.parse(json);
profile.provider = 'github';
profile._raw = body;
@@ -141,7 +150,7 @@ Strategy.prototype.userProfile = function(accessToken, done) {
// information that was obtained.
return done(null, profile);
}

var json;
try {
json = JSON.parse(body);
@@ -150,15 +159,15 @@ Strategy.prototype.userProfile = function(accessToken, done) {
// information that was obtained.
return done(null, profile);
}


if (!json.length) {
return done(null, profile);
}

profile.emails = profile.emails || [];
var publicEmail = profile.emails[0];

(json).forEach(function(email) {
if (publicEmail && publicEmail.value == email.email) {
profile.emails[0].primary = email.primary;