Skip to content

Commit

Permalink
Upgrade Facebook Graph API to use v2.8
Browse files Browse the repository at this point in the history
In testing for #7715, I discovered that the v2.2 Graph API endpoint was still in use in the `facebook` package which was due to sunset on 2017-03-25.

See Facebook Graph API Changelog here:
  https://developers.facebook.com/docs/apps/changelog

When a Graph API endpoint is sunset, it (is claimed) to automatically turn over to the next more recent version, in this case v2.3.

v2.3 has a breaking-change over v2.2, notably listed in "Changes from v2.2 to v2.3":

> [Oauth Access Token] Format - The response format of https://www.facebook.com/v2.3/oauth/access_token returned when you exchange a code for an access_token now return valid JSON instead of being URL encoded. The new format of this response is {"access_token": {TOKEN}, "token_type":{TYPE}, "expires_in":{TIME}}. We made this update to be compliant with section 5.1 of RFC 6749.

This change updates both Graph APIs to v2.8 which has LTS until "At least October 2018".
  • Loading branch information
abernix committed Feb 10, 2017
1 parent 12f3595 commit 873f13d
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions packages/facebook-oauth/facebook_server.js
@@ -1,7 +1,5 @@
Facebook = {};

var querystring = Npm.require('querystring');

Facebook.handleAuthFromAccessToken = function handleAuthFromAccessToken(accessToken, expiresAt) {
// include all fields from facebook
// http://developers.facebook.com/docs/reference/login/public-profile-and-friend-list/
Expand Down Expand Up @@ -54,30 +52,21 @@ var getTokenResponse = function (query) {
try {
// Request an access token
responseContent = HTTP.get(
"https://graph.facebook.com/v2.2/oauth/access_token", {
"https://graph.facebook.com/v2.8/oauth/access_token", {
params: {
client_id: config.appId,
redirect_uri: OAuth._redirectUri('facebook', config),
client_secret: OAuth.openSecret(config.secret),
code: query.code
}
}).content;
}).data;
} catch (err) {
throw _.extend(new Error("Failed to complete OAuth handshake with Facebook. " + err.message),
{response: err.response});
}

// If 'responseContent' parses as JSON, it is an error.
// XXX which facebook error causes this behvaior?
if (isJSON(responseContent)) {
throw new Error("Failed to complete OAuth handshake with Facebook. " + responseContent);
}

// Success! Extract the facebook access token and expiration
// time from the response
var parsedResponse = querystring.parse(responseContent);
var fbAccessToken = parsedResponse.access_token;
var fbExpires = parsedResponse.expires;
var fbAccessToken = responseContent.access_token;
var fbExpires = responseContent.expires_in;

if (!fbAccessToken) {
throw new Error("Failed to complete OAuth handshake with facebook " +
Expand All @@ -91,7 +80,7 @@ var getTokenResponse = function (query) {

var getIdentity = function (accessToken, fields) {
try {
return HTTP.get("https://graph.facebook.com/v2.4/me", {
return HTTP.get("https://graph.facebook.com/v2.8/me", {
params: {
access_token: accessToken,
fields: fields
Expand Down

3 comments on commit 873f13d

@williamledoux
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it on purpose that the facebook_client.js file still uses API v2.2 ?

@abernix
Copy link
Contributor Author

@abernix abernix commented on 873f13d May 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@williamledoux Good question! Not that I'm aware of. I didn't encounter an issue with that aspect of it when I submitted this, but it's possible that there were no incompatibilities with the dialog aspect of the auth process and that Facebook automatically rolled that call into the v2.3 API, which was backward compatible. If you could reproduce a problem (if any!), test the update to a newer API (v2.8 or v2.9) and submit a pull-request that would be greatly appreciated!

@williamledoux
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I cannot make a simple facebook login example work (see my thread). I tried to make my own version of facebook-oauth with a v2.8 or v2.9 call but It did not fix the problem. So I am stuck, both for fixing my app and for submitting a pull request on this topic.

Please sign in to comment.