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

Updated to v2.8 of graph API #199

Open
wants to merge 1 commit 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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,18 @@ by it. If desired, this fragment can be removed on the client side. Refer to
this [discussion](http://stackoverflow.com/questions/7131909/facebook-callback-appends-to-return-url) on
Stack Overflow for recommendations on how to accomplish such removal.

##### What version of the graph API does this use?

By default, all calls are made to **v2.8** of the graph API. You can modify this by setting the `graphApiVersion` option when creating the strategy.

```js
new FacebookStrategy({
clientID: FACEBOOK_APP_ID,
clientSecret: FACEBOOK_APP_SECRET,
callbackURL: "http://localhost:3000/auth/facebook/callback",
graphApiVersion: 'v2.6'
}, ...)
```

## Contributing

Expand Down
21 changes: 11 additions & 10 deletions lib/strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ 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 graphApiVersion = options.graphApiVersion || 'v2.8';
options.authorizationURL = options.authorizationURL || 'https://www.facebook.com/' + graphApiVersion + '/dialog/oauth';
options.tokenURL = options.tokenURL || 'https://graph.facebook.com/' + graphApiVersion + '/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/' + graphApiVersion + '/me';
this._profileFields = options.profileFields || null;
this._enableProof = options.enableProof;
this._clientSecret = options.clientSecret;
Expand Down Expand Up @@ -100,7 +101,7 @@ Strategy.prototype.authorizationParams = function (options) {
if (options.display) {
params.display = options.display;
}

// https://developers.facebook.com/docs/facebook-login/reauthentication/
if (options.authType) {
params.auth_type = options.authType;
Expand Down Expand Up @@ -141,7 +142,7 @@ Strategy.prototype.userProfile = function(accessToken, done) {
// secret as the key.
//
// For further details, refer to:
// https://developers.facebook.com/docs/reference/api/securing-graph-api/
// https://developers.facebook.com/docs/reference/api/securing-graph-api/
var proof = crypto.createHmac('sha256', this._clientSecret).update(accessToken).digest('hex');
url.search = (url.search ? url.search + '&' : '') + 'appsecret_proof=' + proof;
}
Expand All @@ -153,20 +154,20 @@ Strategy.prototype.userProfile = function(accessToken, done) {

this._oauth2.get(url, accessToken, function (err, body, res) {
var json;

if (err) {
if (err.data) {
try {
json = JSON.parse(err.data);
} catch (_) {}
}

if (json && json.error && typeof json.error == 'object') {
return done(new FacebookGraphAPIError(json.error.message, json.error.type, json.error.code, json.error.error_subcode, json.error.fbtrace_id));
}
return done(new InternalOAuthError('Failed to fetch user profile', err));
}

try {
json = JSON.parse(body);
} catch (ex) {
Expand Down Expand Up @@ -217,9 +218,9 @@ Strategy.prototype._convertProfileFields = function(profileFields) {
'emails': 'email',
'photos': 'picture'
};

var fields = [];

profileFields.forEach(function(f) {
// return raw Facebook profile field to support the many fields that don't
// map cleanly to Portable Contacts
Expand Down
Loading