Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allow specifying a profileURL option.

  • Loading branch information...
commit e63e3ab5f4f24756f949c8e19b7ebc7ad63591fc 1 parent e944154
@jaredhanson authored
Showing with 53 additions and 1 deletion.
  1. +2 −1  lib/passport-facebook/strategy.js
  2. +51 −0 test/strategy-test.js
View
3  lib/passport-facebook/strategy.js
@@ -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;
}
@@ -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 : '');
View
51 test/strategy-test.js
@@ -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({
Please sign in to comment.
Something went wrong with that request. Please try again.