0

I have been researching this issue for days now, pulling my hair out. Another thread that most accurately describes my issue is here, but the suggested solution did not work for me.

I'm creating a cross-platform mobile app using Xamarin Forms, and I am trying to integrate Facebook Login as my means of user authentication. I'm presenting the login page modally, rendering the page in a platform specific manner in each of the mobile platform projects, and using the Xamarin.Auth API to handle the bulk of the authentication. The following snippit is from the Android implementaiton:

        var activity = Context as Activity;
        var authenticator = new OAuth2Authenticator(
            clientId: AppConstants.FacebookAppId,
            scope: "",
            authorizeUrl: AppConstants.FacebookAuthorizeUri,
            redirectUrl: AppConstants.FacebookRedirectUri);
        authenticator.Completed += async (sender, eventArgs) => 
        {
            // Check for authentication, call Graph API, deserialize JSON, etc...
        };
        activity.StartActivity(authenticator.GetUI(activity));

This is the boiler-plate code that basically every online example gives, and should present a Facebook Login page. However, after clicking my Login with Facebook button, which should push the rendered page modally, all I get is this:

Facebook Login Error

"Not logged in: You are not logged in. Please login and try again."

I have double and triple checked that the clientId parameter matches my Facebook App ID on my Facebook Developer Console. I have made sure that the redirect and authorization URIs supplied to the OAuth2Authenticator object are correct. I have added the redirect URI to my Facebook Developer Console. My development keyhash, found using keytool and openssl is also correct. My package name and class name (package.name.MainActivity) are also correct in the console (the package name in my project was set manually by double-clicking the Android project, going to 'Android Manifest', and putting in my own package name). I have removed and readded the Android project from the Facebook Developer Console several times over.

My question is, are there any other steps specific to the Xamarin platform that I may be missing here? I really don't know what the error seems to be. I'd appreciate any help/input on the matter.

Thanks in advance.

Community
  • 1
  • 1
David O'Neill
  • 330
  • 2
  • 13
  • What did you put for you Authorize and Redirect URLs? Even an abbreviated version of the redirect URL would be helpful. – hvaughan3 Sep 10 '16 at 21:14
  • `authorizeUrl` is set to https://m.facebook.com/dialog/oauth/ `redirectUrl` is set to http://www.facebook.com/connect/login_success.html. Let me know if there's anything else you might need. – David O'Neill Sep 11 '16 at 09:26
  • Yea thats exactly what I have. In the Facebook developer site, did you enabled the **Facebook Login** Product? Within **Facebook Login**, I also enabled **Client OAuth Login**, **Web OAuth Login**, and **Embedded Browser OAuth Login** although you may not need to enabled all of those. I also left **Deauthorize Callback** empty – hvaughan3 Sep 11 '16 at 15:48
  • Yes, Facebook Login is my only Facebook "Product." I too have Client OAuth Login, Web OAuth Login, and Embedded Browswer OAuth Login. Deauthorize Callback is empty. – David O'Neill Sep 11 '16 at 17:15
  • Do you happen to see any JavaScript error in the output window generated by the WebView? You might also look in the DDMS output window to see if you get any more helpful info there. What happens when you completely uninstall the app from the device and try again? I wonder if it is a saved cookie error or something... Also, you can try to create a new test user from the Facebook developer site and login with that to see if it makes any difference: Facebook Dev Site -> Roles -> Test User -> Add – hvaughan3 Sep 11 '16 at 19:06

1 Answers1

0

I've managed to get this to work, but the solution doesn't make sense to me... In my valid redirect URIs list on the Facebook Developer console, I went back and listed both the redirectUrl and the authorizeUrl (m.facebook.dialog/oauth and facebook.com/connect/login_success.html). Some people might see this and say, "Well, duh!" But I did quite a bit of reading/researching both the documentation Facebook provides, as well as developer blogs/videos, and no one else I saw put both URLs.

So, my advice, put BOTH URLs in the Developer Console as valid redirect URLs.

David O'Neill
  • 330
  • 2
  • 13