Skip to content
Browse files

Merge pull request #18 from troupe/authenticated_profile_requests

Authenticated profile requests
  • Loading branch information...
2 parents 99208e7 + 74ed093 commit 46ee2a481513ab1855908102f2d66dd9e527a4d6 @jaredhanson committed Mar 9, 2014
Showing with 11 additions and 8 deletions.
  1. +10 −7 lib/passport-github/strategy.js
  2. +1 −1 package.json
View
17 lib/passport-github/strategy.js
@@ -24,7 +24,7 @@ var util = require('util')
* - `scope` array of permission scopes to request. valid scopes include:
* 'user', 'public_repo', 'repo', 'gist', or none.
* (see http://developer.github.com/v3/oauth/#scopes for more info)
- * — `userAgent` All API requests MUST include a valid User Agent string.
+ * — `userAgent` All API requests MUST include a valid User Agent string.
* e.g: domain name of your application.
* (see http://developer.github.com/v3/#user-agent-required for more info)
*
@@ -53,13 +53,14 @@ function Strategy(options, verify) {
options.tokenURL = options.tokenURL || 'https://github.com/login/oauth/access_token';
options.scopeSeparator = options.scopeSeparator || ',';
options.customHeaders = options.customHeaders || {};
-
+
if (!options.customHeaders['User-Agent']) {
options.customHeaders['User-Agent'] = options.userAgent || 'passport-github';
}
-
+
OAuth2Strategy.call(this, options, verify);
this.name = 'github';
+ this._oauth2.useAuthorizationHeaderforGET(true);
this._userProfileURL = options.userProfileURL || 'https://api.github.com/user';
}
@@ -86,22 +87,24 @@ util.inherits(Strategy, OAuth2Strategy);
* @api protected
*/
Strategy.prototype.userProfile = function(accessToken, done) {
+ if(!accessToken) return done(new InternalOAuthError('accessToken not supplied', err));
+
this._oauth2.get(this._userProfileURL, accessToken, function (err, body, res) {
if (err) { return done(new InternalOAuthError('failed to fetch user profile', err)); }
-
+
try {
var json = JSON.parse(body);
-
+
var profile = { provider: 'github' };
profile.id = json.id;
profile.displayName = json.name;
profile.username = json.login;
profile.profileUrl = json.html_url;
profile.emails = [{ value: json.email }];
-
+
profile._raw = body;
profile._json = json;
-
+
done(null, profile);
} catch(e) {
done(e);
View
2 package.json
@@ -1,6 +1,6 @@
{
"name": "passport-github",
- "version": "0.1.6",
+ "version": "0.1.7",
"description": "GitHub authentication strategy for Passport.",
"keywords": ["passport", "github", "auth", "authn", "authentication", "identity"],
"repository": {

0 comments on commit 46ee2a4

Please sign in to comment.
Something went wrong with that request. Please try again.