Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Login - Windows 10 UWP - Desktop

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.

like image 954
David Hamilton Avatar asked Oct 13 '15 08:10

David Hamilton


People also ask

Is UWP discontinued?

Microsoft continues to baby-step around the obvious, but it has officially deprecated the Universal Windows Platform (UWP) as it pushes the desktop-focused Windows App SDK (formerly called Project Reunion) and WinUI 3 as the future of Windows application development.

What does Windows 10 UWP mean?

Windows 10 introduced the Universal Windows Platform (UWP), which provides a common app platform on every device that runs Windows. The UWP core APIs are the same on all Windows devices.

What is UWP desktop?

(Universal Windows Platform) Introduced with Windows 10, UWP is a common programming platform for all Microsoft products, including Windows, Xbox, Surface Hub and HoloLens. Applications written as UWP programs perform across all Windows devices, but rather than target an OS version, developers specify a device family.


2 Answers

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;
  }
}
like image 114
sibbl Avatar answered Nov 26 '22 23:11

sibbl


Use WebAuthenticationBroker.GetCurrentApplicationCallbackUri().AbsoluteUri for redirect_uri.

And update the same uri in facebook developer console.

https://developers.facebook.com/apps//settings/

Facebook developer console

like image 34
sunny_iexceed Avatar answered Nov 27 '22 00:11

sunny_iexceed