Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update default graph-version to v3.0 #83

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "passport-facebook-token",
"version": "3.3.0",
"version": "3.3.1",
"description": "Facebook token authentication strategy for Passport",
"main": "lib/index.js",
"scripts": {
Expand Down
5 changes: 2 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@ import { OAuth2Strategy, InternalOAuthError } from 'passport-oauth';
* clientID: '123456789',
* clientSecret: 'shhh-its-a-secret'
* }), (accessToken, refreshToken, profile, done) => {
* User.findOrCreate({facebookId: profile.id}, done);
* User.findOrCreate({ facebookId: profile.id }, done);
* });
*/
export default class FacebookTokenStrategy extends OAuth2Strategy {
constructor(_options, _verify) {
const options = _options || {};
const verify = _verify;
const _fbGraphVersion = options.fbGraphVersion || 'v2.6';
const _fbGraphVersion = options.fbGraphVersion || 'v3.0';


options.authorizationURL = options.authorizationURL || `https://www.facebook.com/${_fbGraphVersion}/dialog/oauth`;
options.tokenURL = options.tokenURL || `https://graph.facebook.com/${_fbGraphVersion}/oauth/access_token`;

Expand Down
16 changes: 8 additions & 8 deletions test/unit/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ describe('FacebookTokenStrategy:init', () => {

it('Should use the default fb graph version when no explicit version is specified', () => {
let strategy = new FacebookTokenStrategy(STRATEGY_CONFIG, BLANK_FUNCTION);
assert.equal(strategy._fbGraphVersion, 'v2.6');
assert.equal(strategy._oauth2._accessTokenUrl,'https://graph.facebook.com/v2.6/oauth/access_token');
assert.equal(strategy._oauth2._authorizeUrl,'https://www.facebook.com/v2.6/dialog/oauth');
assert.equal(strategy._profileURL,'https://graph.facebook.com/v2.6/me');
assert.equal(strategy._fbGraphVersion, 'v3.0');
assert.equal(strategy._oauth2._accessTokenUrl,'https://graph.facebook.com/v3.0/oauth/access_token');
assert.equal(strategy._oauth2._authorizeUrl,'https://www.facebook.com/v3.0/dialog/oauth');
assert.equal(strategy._profileURL,'https://graph.facebook.com/v3.0/me');
});

it('Should use the explicit version, if specified', () => {
Expand Down Expand Up @@ -316,7 +316,7 @@ describe('FacebookTokenStrategy:userProfile', () => {
assert.equal(profile.name.givenName, 'Eugene');
assert.equal(profile.gender, 'male');
assert.equal(profile.emails[0].value, '[email protected]');
assert.equal(profile.photos[0].value, 'https://graph.facebook.com/v2.6/794955667239296/picture?type=large');
assert.equal(profile.photos[0].value, 'https://graph.facebook.com/v3.0/794955667239296/picture?type=large');
assert.equal(typeof profile._raw, 'string');
assert.equal(typeof profile._json, 'object');

Expand Down Expand Up @@ -349,7 +349,7 @@ describe('FacebookTokenStrategy:userProfile', () => {
sinon.stub(strategy._oauth2, 'get', (url, accessToken, next) => next(null, fakeProfile, null));

strategy.userProfile('accessToken', (error, profile) => {
assert.equal(strategy._oauth2.get.getCall(0).args[0], 'https://graph.facebook.com/v2.6/me?appsecret_proof=8c340bd01643ab69939ca971314d7a3d64bfb18946cdde566f12fdbf6707d182&fields=id,name,last_name,first_name,middle_name,email');
assert.equal(strategy._oauth2.get.getCall(0).args[0], 'https://graph.facebook.com/v3.0/me?appsecret_proof=8c340bd01643ab69939ca971314d7a3d64bfb18946cdde566f12fdbf6707d182&fields=id,name,last_name,first_name,middle_name,email');
strategy._oauth2.get.restore();
done();
});
Expand All @@ -365,7 +365,7 @@ describe('FacebookTokenStrategy:userProfile', () => {
sinon.stub(strategy._oauth2, 'get', (url, accessToken, next) => next(null, fakeProfile, null));

strategy.userProfile('accessToken', (error, profile) => {
assert.equal(strategy._oauth2.get.getCall(0).args[0], 'https://graph.facebook.com/v2.6/me?appsecret_proof=8c340bd01643ab69939ca971314d7a3d64bfb18946cdde566f12fdbf6707d182&fields=last_name,first_name,middle_name,custom');
assert.equal(strategy._oauth2.get.getCall(0).args[0], 'https://graph.facebook.com/v3.0/me?appsecret_proof=8c340bd01643ab69939ca971314d7a3d64bfb18946cdde566f12fdbf6707d182&fields=last_name,first_name,middle_name,custom');
strategy._oauth2.get.restore();
done();
});
Expand Down Expand Up @@ -398,7 +398,7 @@ describe('FacebookTokenStrategy:userProfile', () => {
strategy.userProfile('accessToken', (error, profile) => {
if (error) return done(error);

assert.equal(profile.photos[0].value, 'https://graph.facebook.com/v2.6/794955667239296/picture?width=1520&height=1520');
assert.equal(profile.photos[0].value, 'https://graph.facebook.com/v3.0/794955667239296/picture?width=1520&height=1520');

strategy._oauth2.get.restore();
done();
Expand Down