Skip to content

Commit

Permalink
Update to version 3.2 of Graph API.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed Jan 22, 2019
1 parent a41068e commit ea70721
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
8 changes: 5 additions & 3 deletions lib/strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ var OAuth2Strategy = require('passport-oauth2')
*/
function Strategy(options, verify) {
options = options || {};
options.authorizationURL = options.authorizationURL || 'https://www.facebook.com/dialog/oauth';
options.tokenURL = options.tokenURL || 'https://graph.facebook.com/oauth/access_token';
var version = options.graphAPIVersion || 'v3.2';

options.authorizationURL = options.authorizationURL || 'https://www.facebook.com/' + version + '/dialog/oauth';
options.tokenURL = options.tokenURL || 'https://graph.facebook.com/' + version + '/oauth/access_token';
options.scopeSeparator = options.scopeSeparator || ',';

OAuth2Strategy.call(this, options, verify);
this.name = 'facebook';
this._profileURL = options.profileURL || 'https://graph.facebook.com/v2.5/me';
this._profileURL = options.profileURL || 'https://graph.facebook.com/' + version + '/me';
this._profileFields = options.profileFields || null;
this._enableProof = options.enableProof;
this._clientSecret = options.clientSecret;
Expand Down
12 changes: 6 additions & 6 deletions test/strategy.profile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Strategy#userProfile', function() {
}, function() {});

strategy._oauth2.get = function(url, accessToken, callback) {
if (url != 'https://graph.facebook.com/v2.5/me') { return callback(new Error('incorrect url argument')); }
if (url != 'https://graph.facebook.com/v3.2/me') { return callback(new Error('incorrect url argument')); }
if (accessToken != 'token') { return callback(new Error('incorrect token argument')); }

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"}';
Expand Down Expand Up @@ -63,7 +63,7 @@ describe('Strategy#userProfile', function() {
}, function() {});

strategy._oauth2.get = function(url, accessToken, callback) {
if (url != 'https://graph.facebook.com/v2.5/me?appsecret_proof=e941110e3d2bfe82621f0e3e1434730d7305d106c5f68c87165d0b27a4611a4a') { return callback(new Error('incorrect url argument')); }
if (url != 'https://graph.facebook.com/v3.2/me?appsecret_proof=e941110e3d2bfe82621f0e3e1434730d7305d106c5f68c87165d0b27a4611a4a') { return callback(new Error('incorrect url argument')); }
if (accessToken != 'token') { return callback(new Error('incorrect token argument')); }

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"}';
Expand Down Expand Up @@ -96,7 +96,7 @@ describe('Strategy#userProfile', function() {
}, function() {});

strategy._oauth2.get = function(url, accessToken, callback) {
if (url != 'https://graph.facebook.com/v2.5/me?fields=id,username,name,last_name,first_name,middle_name,gender,link,email,picture') { return callback(new Error('incorrect url argument')); }
if (url != 'https://graph.facebook.com/v3.2/me?fields=id,username,name,last_name,first_name,middle_name,gender,link,email,picture') { return callback(new Error('incorrect url argument')); }
if (accessToken != 'token') { return callback(new Error('incorrect token argument')); }

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"}';
Expand Down Expand Up @@ -130,7 +130,7 @@ describe('Strategy#userProfile', function() {
}, function() {});

strategy._oauth2.get = function(url, accessToken, callback) {
if (url != 'https://graph.facebook.com/v2.5/me?appsecret_proof=e941110e3d2bfe82621f0e3e1434730d7305d106c5f68c87165d0b27a4611a4a&fields=id,username,name,last_name,first_name,middle_name,gender,link,email,picture') { return callback(new Error('incorrect url argument')); }
if (url != 'https://graph.facebook.com/v3.2/me?appsecret_proof=e941110e3d2bfe82621f0e3e1434730d7305d106c5f68c87165d0b27a4611a4a&fields=id,username,name,last_name,first_name,middle_name,gender,link,email,picture') { return callback(new Error('incorrect url argument')); }
if (accessToken != 'token') { return callback(new Error('incorrect token argument')); }

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"}';
Expand Down Expand Up @@ -163,7 +163,7 @@ describe('Strategy#userProfile', function() {
}, function() {});

strategy._oauth2.get = function(url, accessToken, callback) {
if (url != 'https://graph.facebook.com/v2.5/me?fields=id,username,name,last_name,first_name,middle_name,gender,link,email,picture,public_key,updated_time') { return callback(new Error('incorrect url argument')); }
if (url != 'https://graph.facebook.com/v3.2/me?fields=id,username,name,last_name,first_name,middle_name,gender,link,email,picture,public_key,updated_time') { return callback(new Error('incorrect url argument')); }
if (accessToken != 'token') { return callback(new Error('incorrect token argument')); }

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", "updated_time": "2013-11-02T18:33:09+0000"}';
Expand Down Expand Up @@ -200,7 +200,7 @@ describe('Strategy#userProfile', function() {
}, function() {});

strategy._oauth2.get = function(url, accessToken, callback) {
if (url != 'https://graph.facebook.com/v2.5/me') { return callback(new Error('incorrect url argument')); }
if (url != 'https://graph.facebook.com/v3.2/me') { return callback(new Error('incorrect url argument')); }
if (accessToken != 'token') { return callback(new Error('incorrect token argument')); }

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"}';
Expand Down
4 changes: 2 additions & 2 deletions test/strategy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('Strategy', function() {
});

it('should be redirected', function() {
expect(url).to.equal('https://www.facebook.com/dialog/oauth?display=mobile&response_type=code&client_id=ABC123');
expect(url).to.equal('https://www.facebook.com/v3.2/dialog/oauth?display=mobile&response_type=code&client_id=ABC123');
});
});

Expand All @@ -73,7 +73,7 @@ describe('Strategy', function() {
});

it('should be redirected', function() {
expect(url).to.equal('https://www.facebook.com/dialog/oauth?auth_type=reauthenticate&auth_nonce=foo123&response_type=code&client_id=ABC123');
expect(url).to.equal('https://www.facebook.com/v3.2/dialog/oauth?auth_type=reauthenticate&auth_nonce=foo123&response_type=code&client_id=ABC123');
});
});

Expand Down

0 comments on commit ea70721

Please sign in to comment.