Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
rebase to 0.0.2
  • Loading branch information
jozzhart committed Mar 6, 2013
1 parent f942428 commit ba3853d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
38 changes: 19 additions & 19 deletions lib/passport-youtube/strategy.js
Expand Up @@ -4,8 +4,8 @@
var util = require('util')
, OAuth2Strategy = require('passport-oauth').OAuth2Strategy
, InternalOAuthError = require('passport-oauth').InternalOAuthError;


/**
* `Strategy` constructor.
*
Expand All @@ -20,17 +20,17 @@ function Strategy(options, verify) {
options.authorizationURL = options.authorizationURL || 'https://accounts.google.com/o/oauth2/auth';
options.tokenURL = options.tokenURL || 'https://accounts.google.com/o/oauth2/token';
options.scopeSeparator = options.scopeSeparator || ',';

OAuth2Strategy.call(this, options, verify);
this.name = 'youtube';
this._profileURL = options.profileURL || 'https://gdata.youtube.com/feeds/api/users/default?alt=json';
}

/**
* Inherit from `OAuth2Strategy`.
*/
util.inherits(Strategy, OAuth2Strategy);

/**
* Retrieve user profile from Youtube.
*
Expand All @@ -49,57 +49,57 @@ util.inherits(Strategy, OAuth2Strategy);
*/
Strategy.prototype.userProfile = function(accessToken, done) {
var url = this._profileURL;

this._oauth2.getProtectedResource(url, accessToken, function (err, body, res) {

if (err) { return done(new InternalOAuthError('failed to fetch user profile', err)); }

try {
var json = JSON.parse(body);

var youtubeProfile = json.entry;

var profile = { provider: 'youtube' };
profile.id = youtubeProfile["yt$googlePlusUserId"]["$t"];
profile.username = youtubeProfile["yt$username"]["$t"];
profile.displayName = youtubeProfile["title"]["$t"];
profile.name = { familyName: youtubeProfile["yt$lastName"]["$t"],
givenName: youtubeProfile["yt$firstName"]["$t"]};

profile._raw = body;
profile._json = json;

done(null, profile);
} catch(e) {
done(e);
}
});
}

Strategy.prototype._convertProfileFields = function(profileFields) {
var map = {
'id': 'id',
'username': 'username',
'displayName': 'name',
'name': ['last_name', 'first_name']
};

var fields = [];

profileFields.forEach(function(f) {
if (typeof map[f] === 'undefined') return;

if (Array.isArray(map[f])) {
Array.prototype.push.apply(fields, map[f]);
} else {
fields.push(map[f]);
}
});

return fields.join(',');
}

/**
* Expose `Strategy`.
*/
module.exports = Strategy;
module.exports = Strategy;
8 changes: 4 additions & 4 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "passport-youtube",
"version": "0.0.4",
"version": "0.0.2",
"description": "Youtube OAuth2 authentication strategy for Passport. Based on the passport-facebook module",
"keywords": [
"passport",
Expand Down Expand Up @@ -30,14 +30,14 @@
"main": "./lib/passport-youtube",
"dependencies": {
"pkginfo": "0.2.x",
"passport-oauth": "~0.1.2"
"passport-oauth": "0.1.14"
},
"devDependencies": {},
"scripts": {},
"engines": {
"node": ">= 0.8.0"
},
"readme": "passport-youtube\n================\n\nYoutube strategy for passport",
"_id": "passport-youtube@0.0.3",
"_from": "passport-youtube@"
"_id": "passport-youtube@0.0.2",
"_from": "passport-youtube@0.0.2"
}

0 comments on commit ba3853d

Please sign in to comment.