Cannot get Facebook single signon with windows 8.1 to work

二次信任 提交于 2019-12-06 11:36:25

问题


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 ?


回答1:


this issue has been resolved. Can you please give this a try and let us know if you are still seeing the issue?




回答2:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!