Mark Gibaud
Mark Gibaud

Reputation: 2061

Integrating a Xamarin app with Facebook SSO w/ Facebook iOS App

I am writing a Xamarin iOS app and having difficulty integrating Facebook SSO, though I don't think my problem is necessarily Xamarin-specific, just a lack of understanding of how to integrate Facebook SSO without the benefit of the Facebook iOS SDK.

I have followed the various guides and have done the following:

1) Have a Facebook App set up: a) iOS Platform added with bundle id matching my app's bundle id b) Single sign on enabled

2) Set up my info.plist as follows: info.plist

raw text:

<key>CFBundleDisplayName</key>
<string>[company]</string>
<key>CFBundleIdentifier</key>
<string>com.[company].ios.app</string>
<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>fb123490xxx</string>
        </array>
        <key>CFBundleURLName</key>
        <string>com.[company].ios.app</string>
    </dict>
</array>
<key>FacebookAppID</key>
<string>123490xxx</string>
<key>FacebookDisplayName</key>
<string>[company] Staging</string>

3) Implemented the following code in my app:

FacebookLoginButton.TouchUpInside += (sender, e) => 
        {
            var urlWithAppProtocol = new NSUrl("fb123490xxx://");
            UIApplication.SharedApplication.OpenUrl(urlWithAppProtocol);
        };

I have not overriden AppDelegates methods (OpenUrl and HandleOpenUrl) yet because as far as I can see those handle incoming redirects to my app; I will get that working next.

To be clear, what I'm expecting to see is the FB iOS App equivalent of this screen (from Mobile Safari) mobile safari

However, if I redirect to:
"fb://[appid]" I get redirected to the FB app but just to the news feed page (or whatever screen I was on last when I was using the FB app)

"fb[appid]://" I get nothing happening, .OpenUrl() does nothing;

"fb://profile/[appid]" as an experiment, I get the following (notice the "app isn't available for your phone"); this could be because you're supposed to use the PageID with /profile.

profile

What am I missing here?

Upvotes: 0

Views: 1468

Answers (1)

Mark Gibaud
Mark Gibaud

Reputation: 2061

Ok, in the end it was simply using fbauth://authorize in conjunction with the normal query string parameters in the oauth url. The redirect url needs to be fbconnect://success

I found this by reading the source code of the FB iOS SDK:

https://github.com/keithpitt/DKSocial/blob/72cd77bc15ca1a307b92aff8382f2c71a97da7de/External/FBConnect/Facebook.m

There might be a lesson here to use the Xamarin bindings of the official Facebook iOS SDK, which offers this functionality. I've ended up going down the manual route because I started with the Facebook .NET SDK, which doesn't seem to offer this App-based SSO functionality.

Upvotes: 3

Related Questions