Permalink
Browse files

0.0.5

  • Loading branch information...
1 parent 13d309e commit ea0f84d22a3e71563bedc2dc68f929044d4804e4 @jozzhart committed Mar 7, 2013
Showing with 50 additions and 22 deletions.
  1. 0 LICENSE
  2. +28 −1 README.md
  3. 0 lib/passport-youtube/index.js
  4. +19 −19 lib/passport-youtube/strategy.js
  5. +3 −2 package.json
View
0 LICENSE 100644 → 100755
File mode changed.
View
29 README.md 100644 → 100755
@@ -1,4 +1,31 @@
passport-youtube
================
-Youtube strategy for passport
+Youtube strategy for passport
+
+
+
+## Install
+
+ $ npm install passport-youtube
+
+## Usage
+
+#### Configure Strategy
+
+The Youtube authentication strategy authenticates users using a youtube
+account and OAuth 2.0 tokens. The strategy requires a `verify` callback, which
+accepts these credentials and calls `done` providing a user, as well as
+`options` specifying a app ID, app secret, and callback URL.
+
+ passport.use(new YoutubeStrategy({
+ clientID: YOUTUBE_APP_ID,
+ clientSecret: YOUTUBE_APP_SECRET,
+ callbackURL: "http://localhost:3000/auth/youtube/callback"
+ },
+ function(accessToken, refreshToken, profile, done) {
+ User.findOrCreate({ userId: profile.id }, function (err, user) {
+ return done(err, user);
+ });
+ }
+ ));
View
0 lib/passport-youtube/index.js 100644 → 100755
File mode changed.
View
38 lib/passport-youtube/strategy.js 100644 → 100755
@@ -4,8 +4,8 @@
var util = require('util')
, OAuth2Strategy = require('passport-oauth').OAuth2Strategy
, InternalOAuthError = require('passport-oauth').InternalOAuthError;
-
-
+
+
/**
* `Strategy` constructor.
*
@@ -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.
*
@@ -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;
View
5 package.json
@@ -1,6 +1,6 @@
{
"name": "passport-youtube",
- "version": "0.0.4",
+ "version": "0.0.5",
"description": "Youtube OAuth2 authentication strategy for Passport. Based on the passport-facebook module",
"keywords": [
"passport",
@@ -31,7 +31,8 @@
"dependencies": {
"pkginfo": "0.2.x",
"passport": "~0.1.1",
- "oauth": "0.9.x"
+ "oauth": "0.9.x",
+ "passport-oauth": ""
},
"devDependencies": {},
"scripts": {},

0 comments on commit ea0f84d

Please sign in to comment.