After the great news about Facebook and Microsoft support Facebook SSO I have tried to implement this in a winrt/xaml/c# app for windows 8.1, however I cannot get it to work.
I have registered the app with facebook and set the app's SID in the app's settings.
This is the login code:
Uri sid = WebAuthenticationBroker.GetCurrentApplicationCallbackUri();
string callbackURL = sid.ToString();
String facebookURL = "https://www.facebook.com/dialog/oauth?client_id=" + Uri.EscapeDataString(AppId) + "&display=touch&response_type=token&scope=publish_stream&redirect_uri=" + Uri.EscapeDataString(callbackURL);
var startUri = new Uri(facebookURL);
WebAuthenticationResult result = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, startUri);
This will open the Facebook login dialog, I can log in, and the next dialog says "You have already authorized .
But clicking on the "Okay" or "Skip" buttons gives no response back to my app. AuthenticateAsync() never returns.
If I change the &display parameter to "touch" it works, but this is not what I want since it shows a mobile login web page not designed for this purpose.
What is wrong ?
this issue has been resolved. Can you please give this a try and let us know if you are still seeing the issue?
Yes, now it works :-)
This is the code I use, and it works fine:
Uri sid = WebAuthenticationBroker.GetCurrentApplicationCallbackUri();
string callbackURL = sid.ToString();
string facebookURL = "https://www.facebook.com/dialog/oauth?client_id=" + Uri.EscapeDataString(AppId) + "&display=popup&response_type=token&scope=publish_stream&redirect_uri=" + Uri.EscapeDataString(callbackURL);
var startUri = new Uri(facebookURL);
WebAuthenticationResult result = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, startUri, new Uri(callbackURL));
if (result.ResponseStatus == WebAuthenticationStatus.Success && !result.ResponseData.Contains("&error="))
{
string resultString = result.ResponseData.Replace("#", "&");
AccessToken = GetQueryParameter(resultString, "access_token");
wasSuccess = true;
IsLoggedIn = true;
CurrentUser = await FacebookApi.GetCurrentUserId();
}
return wasSuccess;
来源:https://stackoverflow.com/questions/20030744/cannot-get-facebook-single-signon-with-windows-8-1-to-work