Facebook登录 - Windows 10 UWP - 桌面 [英] Facebook Login - Windows 10 UWP - Desktop

查看:170
本文介绍了Facebook登录 - Windows 10 UWP - 桌面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个新的Universal Windows 10 UWP应用程序,并试图进行Facebook登录。



在Facebook上,我已经设置了我的应用程序的Windows应用程序部分具有我的应用程序的标识符:


Windows:s-1-15-xxxxxxxxxxxx

Windows Phone:fef49b712e5a843cbfeb0c9d780423fc (不是实际的)


在包清单文件中,我添加了以下协议:


msft-fef49b712e5a843cbfeb0c9d780423fc


这意味着我设置了我的 redirect_uri 参数:


msft-fef49b712e5a843cbfeb0c9d780423fc://授权


当在手机上运行(使用Windows 10 Mobile Preview)时,该服务工作正常,它打开了手机上的Facebook应用程序(使用fbconnect://授权? ...),然后验证,然后打开我的应用程序备份 - 完美!!



然而当在桌面上尝试相同时,它不起作用。在我的 Launcher.LaunchUriAsync()被设置为具有标准Facebook网络对话框的回退Uri( https://www.facebook.com/dialog/oauth?.... ) - 这是因为没有支持登录的Windows 10的Facebook应用程序。 / p>

将相同的 redirect_uri 发送到Facebook,它打开了Web浏览器(Edge)并要求权限等。一旦提供了权限,没有任何反应。似乎协议处理不起作用。



任何想法都会很有用。

解决方案

在桌面上,请尝试使用 WebAuthenticationBroker 而不是 Launcher.LaunchUriAsync 示例: http://dotnetbyexample.blogspot.de /2015/06/custom-oauth-login-to-facebook-for.html

 私有异步任务<串GT; AuthenticateFacebookAsync()
{
try
{
var fb = new FacebookClient();

var redirectUri =
WebAuthenticationBroker.GetCurrentApplicationCallbackUri()。ToString();

var loginUri = fb.GetLoginUrl(new
{
client_id = AppId,
redirect_uri = redirectUri,
scope = ExtendedPermissions,
display =popup,
response_type =token
});

var callbackUri = new Uri(redirectUri,UriKind.Absolute);

var authenticationResult =
await
WebAuthenticationBroker.AuthenticateAsync(
WebAuthenticationOptions.None,
loginUri,callbackUri);

return ParseAuthenticationResult(fb,authenticationResult);
}
catch(Exception ex)
{
return ex.Message;
}
}


I am building a new Universal Windows 10 UWP App, and trying to do a Facebook login.

On Facebook, I have set the Windows App section of my app to have the identifier of my app:

Windows : s-1-15-xxxxxxxxxxxx
Windows Phone : fef49b712e5a843cbfeb0c9d780423fc (Not the actual one)

In the package manifest file, I have added the protocol of:

msft-fef49b712e5a843cbfeb0c9d780423fc

Which means I set my redirect_uri parameter to:

msft-fef49b712e5a843cbfeb0c9d780423fc://authorize

When running on a phone (with Windows 10 Mobile Preview) the service works fine, it opens up the Facebook app on the phone (using fbconnect://authorize?.....), which in turn authenticates, and then opens my app back up - perfect!!

However, when trying the same on the desktop it doesn't work. In my Launcher.LaunchUriAsync() is set to have a fallback Uri of the standard Facebook web dialog (https://www.facebook.com/dialog/oauth?.....) - This is because there is no Facebook app for Windows 10 that supports login.

Sending the same redirect_uri through to Facebook, it opens up the web browser (Edge) and asks for permissions etc. once the permissions have been given, nothing happens. It seems as though the protocol handling isn't working.

Any thoughts would be useful.

解决方案

On desktop, try using the WebAuthenticationBroker instead of Launcher.LaunchUriAsync as described in this example: http://dotnetbyexample.blogspot.de/2015/06/custom-oauth-login-to-facebook-for.html

private async Task<string> AuthenticateFacebookAsync()
{
  try
  {
    var fb = new FacebookClient();

    var redirectUri = 
      WebAuthenticationBroker.GetCurrentApplicationCallbackUri().ToString();

    var loginUri = fb.GetLoginUrl(new
                                   {
                                     client_id = AppId,
                                     redirect_uri = redirectUri,
                                     scope = ExtendedPermissions,
                                     display = "popup",
                                     response_type = "token"
                                   });

    var callbackUri = new Uri(redirectUri, UriKind.Absolute);

    var authenticationResult =
      await
        WebAuthenticationBroker.AuthenticateAsync(
        WebAuthenticationOptions.None, 
        loginUri, callbackUri);

    return ParseAuthenticationResult(fb, authenticationResult);
  }
  catch (Exception ex)
  {
    return ex.Message;
  }
}

这篇关于Facebook登录 - Windows 10 UWP - 桌面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆