Skip to content

Commit

Permalink
Allow specifying a profileURL option.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed Feb 10, 2013
1 parent e944154 commit e63e3ab
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/passport-facebook/strategy.js
Expand Up @@ -48,6 +48,7 @@ function Strategy(options, verify) {

OAuth2Strategy.call(this, options, verify);
this.name = 'facebook';
this._profileURL = options.profileURL || 'https://graph.facebook.com/me';
this._profileFields = options.profileFields || null;
}

Expand Down Expand Up @@ -99,7 +100,7 @@ Strategy.prototype.authorizationParams = function (options) {
* @api protected
*/
Strategy.prototype.userProfile = function(accessToken, done) {
var url = 'https://graph.facebook.com/me';
var url = this._profileURL;
if (this._profileFields) {
var fields = this._convertProfileFields(this._profileFields);
url += (fields !== '' ? '?fields=' + fields : '');
Expand Down
51 changes: 51 additions & 0 deletions test/strategy-test.js
Expand Up @@ -128,6 +128,57 @@ vows.describe('FacebookStrategy').addBatch({
},
},

'strategy when loading user profile with profileURL option': {
topic: function() {
var strategy = new FacebookStrategy({
clientID: 'ABC123',
clientSecret: 'secret',
profileURL: 'https://graph.facebook.com/me?fields=id,username'
},
function() {});

// mock
strategy._oauth2.getProtectedResource = function(url, accessToken, callback) {
if (url == 'https://graph.facebook.com/me?fields=id,username') {
var body = '{"id":"500308595","name":"Jared Hanson","first_name":"Jared","last_name":"Hanson","link":"http:\\/\\/www.facebook.com\\/jaredhanson","username":"jaredhanson","gender":"male","email":"jaredhanson\\u0040example.com"}';
callback(null, body, undefined);
} else {
callback(new Error('Incorrect user profile URL: ' + url));
}
}

return strategy;
},

'when told to load user profile': {
topic: function(strategy) {
var self = this;
function done(err, profile) {
self.callback(err, profile);
}

process.nextTick(function () {
strategy.userProfile('access-token', done);
});
},

'should not error' : function(err, req) {
assert.isNull(err);
},
'should load profile' : function(err, profile) {
assert.equal(profile.provider, 'facebook');
assert.equal(profile.id, '500308595');
assert.equal(profile.username, 'jaredhanson');
},
'should set raw property' : function(err, profile) {
assert.isString(profile._raw);
},
'should set json property' : function(err, profile) {
assert.isObject(profile._json);
},
},
},

'strategy when loading user profile with mapped profile fields': {
topic: function() {
var strategy = new FacebookStrategy({
Expand Down

0 comments on commit e63e3ab

Please sign in to comment.