abjerner / Skybrud.Social.Facebook

Work in progress...
MIT License
10 stars 9 forks source link

FacebookOAuthClient.GetAccessTokenFromAuthCode returns null #18

Closed azzimuth closed 7 years ago

azzimuth commented 7 years ago

My Facebook integration stopped working and once I debug I see that the FacebookOAuthClient.GetAccessTokenFromAuthCode stopped returning valid access token and returns instead null. Are there any breaking changes in Facebook's API which could cause this? As I said, this was working flawlessly until now.

azzimuth commented 7 years ago

I tested by running the Fiddler and capturing HTTP traffic. I see that the request to graph.facebook.com is successful and an object with valid (as far as I can interpret it) access token is returned by Facebook.

I guess that something is happening in method HttpUtility.ParseQueryString which causes that the ["access_token"] field in the NameValueCollection is null.

abjerner commented 7 years ago

@azzimuth Thanks for reporting :D

I'm not aware that Facebook has changed anything regarding authentication, but I will investigate further.

Btw - are you using Skybrud.Social or Skybrud.Social.Facebook?

azzimuth commented 7 years ago

@abjerner I've found out that I'm using Skybrud.Social and the signature of FacebookOAuthClient.GetAccessTokenFromAuthCode differs from the one in this repository. I will try to replace Skybrud.Social with Skybrud.Social.Facebook.

azzimuth commented 7 years ago

Tried to use the beta NuGet packages but I'm getting some errors saying that Skybrud.Social.Instagram cannot initializea number of classes in Skybrud.Social.Core.

So I'm still stuck with this problem.

abjerner commented 7 years ago

@azzimuth Skybrud.Social is still the stable version, so if you're also using some of the other services supported by this package, it is recommended to keep using it. In the future, each service will be released as an individual package - hence Skybrud.Social.Facebook for Facebook - but this is still work in progress.

Anyways, yesterday Facebook dropped support for v2.2 of the Graph API (newest version is v2.8). I was aware of this, but hadn't noticed that it also affected authentication. From v2.3 and newer versions, Facebook will now return JSON instead of key/value pairs for the various responses received from Facebook during authentication.

I have updated Skybrud.Social to support the JSON in newer versions - you can find the new release here:

https://github.com/abjerner/Skybrud.Social/releases/tag/v0.9.5

The issue still exists in Skybrud.Social.Facebook, but I will look into fixing that as well.

azzimuth commented 7 years ago

@abjerner Great! Thanks a lot! Saw that even the NuGet package was updated :)

mrflo commented 7 years ago

@azzimuth I had exactly the same and found it was JSON using Fiddler as well. Thanks @abjerner for updating ! It's always annoying to have users that can't suddenly log in... Is there a way to make an automated test with notification for Facebook login on a website to avoid future issue ?

abjerner commented 7 years ago

@mrflo Generally Facebook will notify you if your app is configured to use a version of their API that is being deprecated.

The problem with Skybrud.Social was that authentication would always use the oldest version available of the Graph API since Skybrud.Social didn't explicitly specify a version to be used. Even for new Facebook apps only allowed to use v2.8, the authentication page from v2.2 would still be used prior to the 27th of March.

I'm not sure how to make automated tests for authentication. However with the release (v9.5.0), Skybrud.Social will explicitly use v2.3 of the Graph API. This is only the default version - Skybrud.Social has a setting for specifying the version to be used.

In the future, the idea is that Skybrud.Social.Facebook will always use the newest available version of the Graph API, which also means that I - in theory - should catch issues like this before they become a problem for users of my package (given that they update the package now and then).