Android and Facebook Single-Sign-On

Try typing in a completely bogus Key Hash on facebook’s developer web page such as “123”, save your changes, and then re-attempt to log in with your app. You “should” get a log message in your Android log like this…

>> invalid_key:Android key mismatch. Your key “PGv8R2vDQ/w6hexLxdefWKxcYLS"
[import]uid: 32256 topic_id: 35375 reply_id: 140797[/import]

That is what I am currently using. After my generated key didn’t bring any results and I read elsewhere (blog or forums) to use 123.

Right now I am still just trying to get the Facebook sample that comes with corona to work. It has the same issue.

Maybe this logcat output can explain something? This is the output right after I click “Get User” in the corona Facebook sample. Again I only get a Facebook blank white full screen window when it tries to log in.

W/InputManagerService( 187): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@41287d20 (uid=10008 pid=1396)  
D/OpenGLRenderer( 1396): Flushing caches (mode 0)  
I/ActivityManager( 187): Displayed com.facebook.katana/.ProxyAuthDialog: +543ms (total +558ms)  
D/dalvikvm( 1202): GC\_EXPLICIT freed 615K, 12% free 11025K/12423K, paused 5ms+6ms  
W/InputManagerService( 187): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@4136b7c8  
D/dalvikvm( 340): GC\_CONCURRENT freed 391K, 7% free 7559K/8071K, paused 7ms+3ms  
D/AccountTypeManager( 1105): Registering external account type=com.facebook.auth.login, packageName=com.facebook.katana  
W/ResourceType( 1105): getEntry failing because entryIndex 829 is beyond type entryCount 189  
W/ResourceType( 1105): Failure getting entry for 0x7f02033d (t=1 e=829) in package 0 (error -2147483647)  
D/AccountTypeManager( 1105): Registering 1 extension packages  
E/ExternalAccountType( 1105): Unsupported attribute readOnly  
D/AccountTypeManager( 1105): Registering extension package account type=com.google, dataSet=plus, packageName=com.google.android.apps.plus  
I/AccountTypeManager( 1105): Loaded meta-data for 4 account types, 3 accounts in 26ms(wall) 17ms(cpu)  
W/ThrottleService( 187): unable to find stats for iface rmnet0  

Then after I hit the android back button it shows the following.

D/OpenGLRenderer( 1202): Flushing caches (mode 0)  
D/dalvikvm( 1396): GC\_CONCURRENT freed 520K, 27% free 7219K/9863K, paused 2ms+2ms  
D/dalvikvm( 1396): GC\_FOR\_ALLOC freed 111K, 28% free 7165K/9863K, paused 22ms  
I/dalvikvm-heap( 1396): Grow heap (frag case) to 7.887MB for 866416-byte allocation  
D/dalvikvm( 1396): GC\_FOR\_ALLOC freed \<1K, 19% free 8011K/9863K, paused 19ms  
D/dalvikvm( 1396): GC\_FOR\_ALLOC freed \<1K, 19% free 8011K/9863K, paused 17ms  
I/dalvikvm-heap( 1396): Grow heap (frag case) to 8.713MB for 866416-byte allocation  
D/dalvikvm( 1396): GC\_CONCURRENT freed 846K, 19% free 8011K/9863K, paused 3ms+3ms  
I/Corona ( 1396): Facebook Listener events:  
I/Corona ( 1396): type(session)  
I/Corona ( 1396): name(fbconnect)  
I/Corona ( 1396): phase(loginCancelled)  
I/Corona ( 1396): isError(false)  
I/Corona ( 1396): response()  
I/Corona ( 1396): event.name fbconnect  
I/Corona ( 1396): event.type: session  
I/Corona ( 1396): isError: false  
I/Corona ( 1396): didComplete: nil  
I/Corona ( 1396): Session Status: loginCancelled  
D/OpenGLRenderer( 1202): Flushing caches (mode 1)  

Letting it sit on the blank white screen never results in anything. I tried waiting it out just to make sure it wasn’t a connection issue, lag or other odd occurrence.

I know nothing about Android but I see 2 lines in the first output that say failed or failing. Perhaps there in lies my problem?

Appreciate all the help Joshua! [import]uid: 56820 topic_id: 35375 reply_id: 140803[/import]

Also here is a link to a jpg of my Facebook settings. I can’t see anything wrong. I would be happy if it were something I overlooked!

http://www.moonrisegames.com/test/fb1.jpg [import]uid: 56820 topic_id: 35375 reply_id: 140914[/import]

Ok after continuing to research this and not finding anything wrong with my setup, it just kept coming back to that hash key. However no matter what I did I could not get adb logcat to show me the correct hash key. I tried logging it on a Mac and on a Windows 7 machine.

I couldn’t find a direct answer on the Corona Labs site on how to accurately create a hash key. Everything pointed to just put it in wrong, get the error, copy and paste. Apparently that doesn’t work anymore with the new 2.1 Android Facebook app (I am only theorizing). Either way the error wasn’t printing and the Facebook app didn’t give any dialog in it’s window that there was a specific problem. Perhaps they changed something for security reasons? It seems odd to spit the correct hash key out when I see this in red across their developer page if you leave the hash key out:

Error
You have enabled a Facebook Login integration for your app, but have not specified the Key Hashes. For security reasons, the Facebook application will not interact with any native application that does not have a signature that matches a corresponding key hash.

Maybe it just ignores interactions from incorrect hash keys now? More than likely the Facebook app update just broke something.

So, I did get the Corona Facebook sample to work. I had to create the hash manually and found instructions that worked for Windows 7 here (my original hash was created on my Mac):

http://stackoverflow.com/questions/4388992/key-hash-for-android-facebook-app

After popping that hash key in the Facebook page and hitting save, the Corona sample logged right in. When I get home I will have access to my app and I will try it and see if it works with the correct hash key now.

[import]uid: 56820 topic_id: 35375 reply_id: 140949[/import]

I just tested our Facebook sample app that is included with the Corona SDK with my personal app ID on a Kindle Fire HD 7" device:

  • Build 971 without facebook app installed. (Worked)
  • Build 1016 without facebook app installed. (Worked)
  • Build 971 with facebook app installed. (Worked)
  • Build 1016 with facebook app installed. (Worked

Your facebook developer page settings look correct to me. Although, my facebook developer page does not have the “Website with Facebook Login” set up. I tried adding a URL to that section, but facebook logins still worked for me afterwards. I don’t have the “Namespace” or “App Domains” fields set up on my developer page either, but adding say coronalabs.com to app domains didn’t break anything either.

So, I’m not sure what’s going on. You said you tried our Facebook sample app unaltered (other than your appID) and it still doesn’t work for you, right? Because the only other thing I can think of is that maybe your app is logging in with a permission that Facebook no longer supports? I’m merely guessing at this point.

Oh and I hate to ask this question, but are you sure your Android device has Internet access? Are you able to log in successfully via Facebook’s official app?
[import]uid: 32256 topic_id: 35375 reply_id: 140953[/import]

Oh good. You got it working.

I’ve noticed that Facebook has re-arranged the documentation on their website. Instructions on how to generate that hash key can be found under Section 4 via the link below…
https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/
[import]uid: 32256 topic_id: 35375 reply_id: 140957[/import]

Thanks Joshua for the continuing efforts to help understand what’s going on.

I know you have to ask those horribly simple questions, because you never know. However yes, I did have a wireless connection. All my testing today was done on a 3rd device at work. It is an older Motorola Droid. It exhibited the same issues until I got the hash correct.

If you use the latest Facebook App (2.1) and remove your hash key. Do you get the incorrect hash error in the adb logcat like normal or is it suddenly absent? I’d like to think it’s a new bug with the 2.1 app or something. If not, and it’s just me, then there is something odd about my setup that isn’t easily visible. That has me worried it will likely cause me problems moving forward. [import]uid: 56820 topic_id: 35375 reply_id: 140959[/import]

I received the following log message when logging in with an invalid hash key via SSO with Facebook app v2.0 and v2.1.
[lua]D/Facebook-authorize( 3150): Login failed: invalid_key:Android key mismatch. Your key “JGn9F2vDQ/w6hexLxdefCUpxYIA” does not match the allowed keys specified in your application settings. Check your application settings at http://www.facebook.com/developers[/lua]

I’ve noticed that the above only gets logged when tapping the “Okay” button in the top right corner in Facebook’s error window. If you tap the Back button, then the above log message does not get logged. You’re right, the Facebook app’s behavior has changed a bit. We’ll look into documenting this on our end.

Also, the hash key logged above is for Corona’s debug.keystore.

In any case, sorry to hear that facebook has given you so much trouble. I wish they would make it simpler too. [import]uid: 32256 topic_id: 35375 reply_id: 140967[/import]

Ok it’s just me then. Yeah the facebook window that pops up just has Facebook in the header and no buttons anywhere. With the error window not displaying correctly for me I had no way to get that far. It was back button or nothing.

Thanks for checking that out.

I didn’t mention it prior but I really hate Facebook. lol
[import]uid: 56820 topic_id: 35375 reply_id: 140972[/import]