Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Having problems getting the Facebook v4 iOS plugin to login, possibly due to ATS
Started by Alan PlantPot Jan 25 2016 06:30 AM

23 replies to this topic
facebook ios ats
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

Alan PlantPot

[GLOBAL: userInfoPane.html]
Alan PlantPot
  • Contributor

  • 919 posts
  • Corona SDK

I recently updated my copy of Xcode, and with that came the glorious App Transport Security changes.  

I fixed those by updating my plist file accordingly, and then decided I would update the Facebook plugin in my app so that it used the v4 plugin (I'd been putting it off for a while).

 

As far as I can tell I've updated everything correctly as per the migration guide. However when I try to call facebook.login, it switches to the FB app as expected, but then when it comes back to my app the Facebook listener receives the following event:

table: 0x1dcf7560 {
  [type] => "session"
  [name] => "fbconnect"
  [phase] => "loginCancelled"
  [isError] => false
  [response] => ""
}

I don't get receive other events in the listener at all, just the cancelled one. Other than clicking the button in my game which triggers the login call, I haven't touched anything else on screen so I'm definitely not hitting a cancel button.  

In addition, this is an app that I have already signed into FB with,so it doesn't even show me the "do you want to allow this app to sign in" page. It just goes to Facebook and then straight back to my app with no interaction on my part, and then says the login was cancelled.  

The whole process takes maybe...5 seconds so I don't think it's timing out.

 

 

I'm fairly sure related to ATS, but as far as I can tell should not be happening due to my plist settings. When the login call is made I see this in my console:

error: "This app is not allowed to query for scheme fbXXXXXXXXXXXXXX"

where fbXXXXXXXXXXXXXX is my facebook app ID.  

I already have "fbXXXXXXXXXXXXXX" in my plist's LSApplicationQueriesSchemes array, and in NSAppTransportSecurity->NSExceptionDomains I also have facebook.com, graph.facebook.com, fbcdn.net and akamaihd.net

 

All fields also have the following keys:

<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>

What else could be needed in order to get this to work correctly?



[TOPIC: post.html]
#2

Ajay McCaleb

[GLOBAL: userInfoPane.html]
Ajay McCaleb
  • Contributor

  • 209 posts
  • Corona Staff

Hi Alan QuizTix,

 

It looks like Facebook's iOS 9 docs may have changed since the Facebook-v4 docs were originally written. According to those docs now, you should use the key NSThirdPartyExceptionRequiresForwardSecrecy.

 

Also, in your LSApplicationQueriesSchemes array, make sure you've added the following:

<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fbapi20130214</string>
<string>fbapi20130410</string>
<string>fbapi20130702</string>
<string>fbapi20131010</string>
<string>fbapi20131219</string> 
<string>fbapi20140410</string>
<string>fbapi20140116</string>
<string>fbapi20150313</string>
<string>fbapi20150629</string>
<string>fbauth</string>
<string>fbauth2</string>
<string>fb-messenger-api20140430</string>
</array>

The Facebook-v4 plugin currently targets v4.5.0 of the Facebook SDK, so there's a larger amount of content needed in the LSApplicationQueriesSchemes array.

 

Hope that helps.



[TOPIC: post.html]
#3

Alan PlantPot

[GLOBAL: userInfoPane.html]
Alan PlantPot
  • Contributor

  • 919 posts
  • Corona SDK

I've just tried using NSThirdPartyExceptionRequiresForwardSecrecy and NSThirdPartyExceptionAllowsInsecureHTTPLoads but I'm still getting the same response.

 

I already have those strings in my LSApplicationQueriesSchemes array as well, plus the one I mentioned earlier (fbMYAPPID).

 

I'm really not sure what else could be causing the problem.

 

 

Edit: if this is any use, I've added a launch url listener to the app so I can see what is being used to reopen the app in order to return from Facebook:

fbMYAPPID://authorize#e2e=%7B%22init%22%3A1453806352933%7D&expires_in=5101638&signed_request=LOTS_OF_JUMBLED_CHARACTERS&state=%7B%22challenge%22%3A%22Div1PAL3mwpLlxUY2e0AWPRuklk%3D%22%2C%22com.facebook.sdk_client_state%22%3Atrue%2C%223_method%22%3A0%2C%220_auth_logger_id%22%3A%224XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX%22%7D&granted_scopes=user_friends%2Cemail%2Ccontact_email%2Cpublish_actions%2Cpublic_profile&denied_scopes=&access_token=LOTS_OF_JUMBLED_CHARACTERS

I've masked the actual tokens etc, but it looks to me like a valid response has come back. It has an access token, it also shows some granted permissions, and the denied_scopes field is empty. The expires_in time is approx 60 days.



[TOPIC: post.html]
#4

Ajay McCaleb

[GLOBAL: userInfoPane.html]
Ajay McCaleb
  • Contributor

  • 209 posts
  • Corona Staff

Did you add the CoronaDelegates key to your Info.plist as well?

<key>CoronaDelegates</key>
<array>
    <string>CoronaFacebookDelegate</string>
</array>

It's needed to get login working, but our documentation could highlight this a little better than it currently does.



[TOPIC: post.html]
#5

Alan PlantPot

[GLOBAL: userInfoPane.html]
Alan PlantPot
  • Contributor

  • 919 posts
  • Corona SDK

Yes I had already added the CoronaDelegates key.



[TOPIC: post.html]
#6

Ajay McCaleb

[GLOBAL: userInfoPane.html]
Ajay McCaleb
  • Contributor

  • 209 posts
  • Corona Staff

Hi Alan QuizTix,

 

After casually browsing through the Changelog for the iOS Facebook SDK, I came across this note for SDK 4.9.0,

 

"Fixed login bug that treated a request for no new permissions as a cancellation."

 

The iOS version of Facebook-v4 uses Facebook SDK 4.5.1, so it may be worth testing to see if you're hitting this bug. You can do this by adding some arbitrary facebook permission to your facebook.login() call.



[TOPIC: post.html]
#7

Alan PlantPot

[GLOBAL: userInfoPane.html]
Alan PlantPot
  • Contributor

  • 919 posts
  • Corona SDK

Thank you, I'l test this out today. I am making a permission-less request, so it's quite possible this is the cause.



[TOPIC: post.html]
#8

Alan PlantPot

[GLOBAL: userInfoPane.html]
Alan PlantPot
  • Contributor

  • 919 posts
  • Corona SDK

I tried requesting the "public_profile" permission, and that didn't work.  

 

I realise it's granted by default, but if the only way to get login to work is to request a new permission every time, then surely that will violate FB's T&Cs about requesting unneeded permissions (or requesting them before they are needed)?

 

Is this issue also affecting everyone else who is using the plugin, or have I overlooked something?



[TOPIC: post.html]
#9

Ajay McCaleb

[GLOBAL: userInfoPane.html]
Ajay McCaleb
  • Contributor

  • 209 posts
  • Corona Staff

Hmm. Internally, the "public_profile" permission and "user_friends" permissions are always included when facebook.login() occurs.

 

I guess the thing to test to confirm the issue entirely would be to add a permission like "email" to your facebook.login() call and see if that succeeds. Then logout, restart the app, then login again with the same facebook.login() call as before. Assuming that the second call fails, then it sounds like this is in fact the bug you're encountering.



[TOPIC: post.html]
#10

Alan PlantPot

[GLOBAL: userInfoPane.html]
Alan PlantPot
  • Contributor

  • 919 posts
  • Corona SDK

As it turns out, I'd already tested with a non-default permission "user_games_activity" (at least I don't think it's accepted by default), and that hadn't worked. Just tried with "email" and the same thing happened.  

 

I've also just tested with App Transport Security Settings->Allow Arbitrary Loads set to true, just in case there was a request being blocked by ATS. Same thing, it all appears like it's working but then the listener only receives a "loginCancelled" phase.

 

If it's any help, I'm using Xcode 7.2 and Corona Enterprise build 2015.2743 - presumably there is nothing about those builds in particular that should be causing this issue? I could test with a newer Enterprise build, but I'm always reluctant in case something else has been changed in the meantime that I rely on (e.g. when storyboard was deprecated - an easy fix but easy to overlook until you need to update it).



[TOPIC: post.html]
#11

Alan PlantPot

[GLOBAL: userInfoPane.html]
Alan PlantPot
  • Contributor

  • 919 posts
  • Corona SDK

I put this on the back burner while I looked at some Android stuff that I needed to do, and have come back to it today.  

 

I've just updated Corona to the latest daily build 2016.2830 and tried again (I also grabbed the FB-v4 lib again in case it had been updated). I'm still getting the exact same error. As I said in my original posts, the URL used by FB to return to my app makes it seem as though everything is being sent back correctly, but then it always triggers the "cancelled" phase. I've also tried using a brand new Facebook account, just to see if that made any difference (it didn't).

 

Has nobody else ran into this problem? I'm pulling my hair out trying to work out why this is happening.



[TOPIC: post.html]
#12

bgmadclown

[GLOBAL: userInfoPane.html]
bgmadclown
  • Contributor

  • 706 posts
  • Corona SDK

I've seen this right now as I've faced -probably- a similar (or same) issue.

 

I'm having problems when I try to post a link with Facebook v4 integration.

It opens up the Facebook interface for authorization and after that when I try to post the link, it says "the link may be harmful. please enter captcha code" (something like that).

The user enters the code successfully and the share interface with everything I want. The link, image, score of player.

When I press "Share", Facebook redirects me to the Login page saying "you have to log in first" even though I'm logged in and gave the appropriate permissions to the app.

 

I don't think it matters but I'm using daily build 2016.2870.



[TOPIC: post.html]
#13

gsglawson

[GLOBAL: userInfoPane.html]
gsglawson
  • Enthusiast

  • 70 posts
  • Corona SDK

Alan, not sure if you ever got this going or not but I recently ran into the same issue and it required two changes to work.

 

1. Add the NSAllowsArbitraryLoads = true to your build.settings file (which you did)

2. Comment out all of the NSExceptionDomains (see snippet below)

 

I had to do both of those to make ATS happy. I know this is not the safest route but it was the only way I could get it to work.

 

HTH!

Scott


           -- Whitelist Facebook Servers for Network Requests
            NSAppTransportSecurity = 
            {
                  NSAllowsArbitraryLoads = true
--                NSExceptionDomains = 
--                {
--                    ["fbcdn.net"] = 
--                    {
--                        NSIncludesSubdomains = true,
--                        NSExceptionRequiresForwardSecrecy = false,
--                        NSExceptionAllowsInsecureHTTPLoads = false,
--                    },
--                    ["facebook.com"] = 
--                    {
--                        NSIncludesSubdomains = true,
--                        NSExceptionRequiresForwardSecrecy = false,
--                        NSExceptionAllowsInsecureHTTPLoads = false,                    },
--                    ["akamaihd.net"] = 
--                    {
--                        NSIncludesSubdomains = true,
--                        NSExceptionRequiresForwardSecrecy = false,
--                        NSExceptionAllowsInsecureHTTPLoads = false,                    },
--                },
            },

 



[TOPIC: post.html]
#14

Alan PlantPot

[GLOBAL: userInfoPane.html]
Alan PlantPot
  • Contributor

  • 919 posts
  • Corona SDK

Thanks Scott, I still didn't have it working and moved onto other things. I'll try this when I next get a chance and hopefully it will work for me too!



[TOPIC: post.html]
#15

stanga

[GLOBAL: userInfoPane.html]
stanga
  • Contributor

  • 193 posts
  • Corona SDK

I have the same issue happening to me - but only to some users (not consistently) and on Android as well as iOS. 

 

The users try to log-in with facebook. They already accepted the permissions before, so the login does not ask for them. Immediately they get the fbconnect event:

type: session
name: fbconnect
phase: loginCancelled
isError: false
response: 


[TOPIC: post.html]
#16

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,068 posts
  • Enterprise

Engineering is aware of the loginCancelled issue. They are investigating.



[TOPIC: post.html]
#17

DragonGameStudio

[GLOBAL: userInfoPane.html]
DragonGameStudio
  • Enthusiast

  • 65 posts
  • Corona SDK

i am facing this problem also, since the google give alert for opensll, and i really need to use new corona sdk to able to use the new openssl plugin, but to be able to use new corona sdk with its new opensll plugin i must change the facebook plugin to v4,

is there any way to use the old facebook plugin, so i can use new corona sdk with new openssl plugin without changing the facebook plugin

 

thanks



[TOPIC: post.html]
#18

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,068 posts
  • Enterprise

You can continue to use the older facebook plugin.

 

Rob



[TOPIC: post.html]
#19

DragonGameStudio

[GLOBAL: userInfoPane.html]
DragonGameStudio
  • Enthusiast

  • 65 posts
  • Corona SDK

i still can nott use the old facebook plugin with corona sdk build number 2910,

here is the error

Module 'facebook' not found:
    no field package.preload['facebook']
    no file '/Users/chandra/Library/Application Support/Corona/Simulator/Plugins/facebook.lua'
    no file '/Users/chandra/Documents/svnx/_12.BaliFied/code/release/1.5/code/Corona/facebook.lua'
    no file '/Applications/CoronaSDK-2910/Corona Simulator.app/Contents/Resources/facebook.lua'
    no file '/Users/chandra/Library/Application Support/Corona/Simulator/Plugins/facebook.dylib'
    no file './facebook.dylib'
    no file '/Applications/CoronaSDK-2910/Corona Simulator.app/Contents/Resources/facebook.dylib'

File: module 'facebook' not found
 

also when i go to https://store.coronalabs.com/plugins?field_primary_category_tid=9&sort_by=title&sort_order=ASC&items_per_page=12

and look up for facebook plugin and i saw the button is "pre-activated" and i can't activate it

 

thank you



[TOPIC: post.html]
#20

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,068 posts
  • Enterprise

Can you post your build.settings?



[TOPIC: post.html]
#21

DragonGameStudio

[GLOBAL: userInfoPane.html]
DragonGameStudio
  • Enthusiast

  • 65 posts
  • Corona SDK

-- Supported values for orientation:
-- portrait, portraitUpsideDown, landscapeLeft, landscapeRight

settings = {
    
    excludeFiles =
       {
        --all = { "*secret.txt", "artwork/*" },
          iphone = { "Icon-*dpi.png" },
          android = { "Icon.png", "512x512.png", "1024x1024.png" }
       },
    orientation =
    {
        default = "portrait",  -- Initial launch orientation
        content = "portrait",  -- Locked orientation of the Corona stage, independent of Native UI elements (iOS only)
        supported = {"portrait" },  -- Table of allowed options for auto-orientation
    },
        
    plugins =
    {
        ["CoronaProvider.native.popup.social"] =
        {
            publisherId = "com.coronalabs"
        },
        ["plugin.photon"] =
        {           
            publisherId = "com.exitgames",
        },
        ["plugin.openssl"] =
        {
           publisherId = "com.coronalabs",
--           supportedPlatforms = { android = true, iphone = true, ["mac-sim"] = true, ["win32-sim"] = true },
        },
--         ["plugin.notifications"] =
--         {
--            publisherId = "com.coronalabs"
--         },
        ["facebook"] =
        {
            publisherId = "com.coronalabs",
            supportedPlatforms = { iphone=true, android=true },
        },
        ["CoronaProvider.gameNetwork.apple"] =
        {
            publisherId = "com.coronalabs",
            supportedPlatforms = { iphone=true }
        },
        ["CoronaProvider.gameNetwork.google"] =
        {
            publisherId = "com.coronalabs",
            supportedPlatforms = { android=true },
        },
        ["plugin.google.iap.v3"] =
        {
            publisherId = "com.coronalabs",
            supportedPlatforms = { android=true }
        },       
        --["plugin.zip"] =
        --{
        --    publisherId = "com.coronalabs"
        --},
        ["plugin.gameanalytics"] =
        {
            publisherId = "com.gameanalytics",
        },
        ["plugin.advertisingId"] =
        {
            publisherId = "com.coronalabs"
        },
        ["plugin.OneSignal"] =
        {
            publisherId = "com.onesignal",
        },
        ["plugin.google.play.services"] =
        {
            publisherId = "com.coronalabs",
            supportedPlatforms = { android=true, ["android-kindle"]=true },
        },
        ["plugin.chartboost"] =
        {
            publisherId = "com.swipeware"
        },
    },
    
    iphone = {
        plist = {
            --UILaunchStoryboardName = "LaunchScreen",            
            CFBundleIconFile = "Icon.png",
            CFBundleIconFiles = {
                "Icon.png",
                "Icon@2x.png",
                "Icon-60.png",
                "Icon-60@2x.png",
                "Icon-60@3x.png",
                "Icon-72.png",
                "Icon-72@2x.png",
                "Icon-76.png",
                "Icon-76@2x.png",
                "Icon-167.png",
                "Icon-Small-40.png",
                "Icon-Small-40@2x.png",
                "Icon-Small-40@3x.png",
                "Icon-Small-50.png",
                "Icon-Small-50@2x.png",
                "Icon-Small.png",
                "Icon-Small@2x.png",
                "Icon-Small@3x.png"
            },            
            -- CoronaWindowMovesWhenKeyboardAppears = true,
            UIBackgroundModes = {"remote-notification"},
            UIApplicationExitsOnSuspend = false,
            UIStatusBarHidden = true,
            UIPrerenderedIcon = true,
            
            UIAppFonts =
            {
                "calibri.ttf",
                "calibrib.ttf",
                "calibrii.ttf",
                "calibriz.ttf"
            },

            FacebookAppID = "XXXXXXXXXX",
            CFBundleURLTypes =
            {
                 {
                    CFBundleURLSchemes =
                    {                     
                      "fbXXXXXXXXXX",
                    }
                 }
            },
            --CFBundleIdentifier = "com.dragongamestudio.dragonslots",
            CFBundleIdentifier = "com.XXXXXXXXXX.XXXXXXXXXX",

            ["URL types"] =
            {
                item =
                {
                    ["URL Schemes"] = { ["Item 0"] = "fbXXXXXXXXXX" },
                },
            },
            
            plist =
            {
                CoronaDelegates = { "CoronaNotificationsDelegate"}
            },
            -- Whitelist Facebook Servers for Network Requests
            NSAppTransportSecurity =
            {
                NSExceptionDomains =
                {
                    ["fbcdn.net"] =
                    {
                        NSIncludesSubdomains = true,
                        NSExceptionRequiresForwardSecrecy = false,
                    },
                    ["facebook.com"] =
                    {
                        NSIncludesSubdomains = true,
                        NSExceptionRequiresForwardSecrecy = false,
                    },                    
                    ["akamaihd.net"] =
                    {
                        NSIncludesSubdomains = true,
                        NSExceptionRequiresForwardSecrecy = false,
                    },               
                    ["api.gameanalytics.com"]={
                        NSIncludesSubdomains = true,
                        NSThirdPartyExceptionAllowsInsecureHTTPLoads = true
                    },
                },
            },

            -- Whitelist Facebook Apps
            LSApplicationQueriesSchemes =
            {
                "fb",
                "fbapi20130214",
                "fbapi20130410",
                "fbapi20140410",
                "fbapi20140116",
                "fbapi20150313",
                "fbapi20150629",
                "fbauth",
                "fbauth2",
                "fb-messenger-api20140430",
            },
        },
    },
    
    android =
    {
        -- coronaWindowMovesWhenKeyboardAppears = true,
        
        googlePlayGamesAppId = "XXXXXXXXXX",
        facebookAppId = "XXXXXXXXXX",  -- Replace XXXXXXXXXX with your Facebook App ID
        CFBundleDisplayName = "XXXXXXXXXX",
        CFBundleName = "com.XXXXXXXXXX.XXXXXXXXXX",
        UIApplicationExitsOnSuspend = false,
        UIPrerenderedIcon = true,
        UIStatusBarHidden = true,
        permissions =
        {
            { name = ".permission.C2D_MESSAGE", protectionLevel = "signature" },
        },
        --usesExpansionFile = true,
        usesPermissions =
        {
            "com.android.vending.BILLING",
            "android.permission.INTERNET",
            "android.permission.READ_PHONE_STATE",
            "android.permission.VIBRATE",
            "android.permission.ACCESS_NETWORK_STATE",
            "android.permission.GET_ACCOUNTS",
            "android.permission.RECEIVE_BOOT_COMPLETED",
            "com.google.android.c2dm.permission.RECEIVE",
            ".permission.C2D_MESSAGE",
            "com.android.vending.CHECK_LICENSE",
            "android.permission.WRITE_EXTERNAL_STORAGE"
        },
        androidPermissions =
        {
            "com.android.vending.BILLING",
            "android.permission.INTERNET",
            "android.permission.READ_PHONE_STATE",
            "android.permission.VIBRATE",
            "android.permission.ACCESS_NETWORK_STATE",
            "android.permission.GET_ACCOUNTS",
            "android.permission.RECEIVE_BOOT_COMPLETED",
            "com.google.android.c2dm.permission.RECEIVE",
            ".permission.C2D_MESSAGE",
            "com.android.vending.CHECK_LICENSE",
            "android.permission.WRITE_EXTERNAL_STORAGE"
        },
    },
}
 



[TOPIC: post.html]
#22

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,068 posts
  • Enterprise

Can you humor me and comment out the supportedPlatforms line for the facebook plugin?



[TOPIC: post.html]
#23

DragonGameStudio

[GLOBAL: userInfoPane.html]
DragonGameStudio
  • Enthusiast

  • 65 posts
  • Corona SDK

i have try that, like this you mean

 

        ["facebook"] =
        {
            publisherId = "com.coronalabs",
--            supportedPlatforms = { iphone=true, android=true },
        },

 

but it still give me error message like above

 

Module 'facebook' not found:
    no field package.preload['facebook']
    no file '/Users/chandra/Library/Application Support/Corona/Simulator/Plugins/facebook.lua'
    no file '/Users/chandra/Documents/svnx/_12myproject/code/release/1.5/code/Corona/facebook.lua'
    no file '/Applications/CoronaSDK-2910/Corona Simulator.app/Contents/Resources/facebook.lua'
    no file '/Users/chandra/Library/Application Support/Corona/Simulator/Plugins/facebook.dylib'
    no file './facebook.dylib'
    no file '/Applications/CoronaSDK-2910/Corona Simulator.app/Contents/Resources/facebook.dylib'

File: module 'facebook' not found



[TOPIC: post.html]
#24

Ajay McCaleb

[GLOBAL: userInfoPane.html]
Ajay McCaleb
  • Contributor

  • 209 posts
  • Corona Staff

Hi DragonGameStudio,

 

From what you've posted, it looks like you're only having this issue with the Corona Simulator. Have you tried building for device?

 

From the Facebook legacy plugin documentation:

  • Starting with daily build 2015.2747, we've removed the Corona Simulator plugin stub for this plugin from Corona SDK. This is to encourage upgrading to the Facebook-v4 plugin.

  • If you do a device build of your project, it should still build successfully with the latest daily build.

  • If you need this Facebook plugin stub for testing in the Corona Simulator, please revert to any daily build prior to 2015.2747.




[topic_controls]
[/topic_controls]