0
votes

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?

1
I have no kownledge about Mono, but call URL fb123490xxx: will just open your app. You are supposed to call some method on either the Facebook SDK or Account store to make get the screen you want.rckoenes
What do you mean by "account store"?; And calling Url "fbxxx" will open the Facebook app right, not my app?Mark Gibaud
No call fbxxxxx where xxxx will be your appId from facebook will open your app not the facebook app. Account store : developer.apple.com/library/ios/documentation/Accounts/…rckoenes
Ah those accounts, thanks - but it looks like that is for the Facebook stuff baked into iOS; I want to basically use OAuth but using the FB App instead of Mobile Safari. So if I OpenUrl "fb://" it goes to facebook - how does that need to change to open FB on my app's page?Mark Gibaud
Since I have zero knowledge of monotouch I'm not sure how that could be done. Normally you just use the Facebook iOS SDKrckoenes

1 Answers

3
votes

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.