Facebook authentication working on one device but not in another one (in debug apk)

Hi community,

First I apologise if this topic has been already raised somewhere else. I am using the awesome ionic 3 framework for developing a simple android app which has facebook authentication. I have used the cordova-plugin-facebook4 from “https://github.com/amritk/cordova-plugin-facebook4.git” and it is working like a charm.

I am creating debug APKs and sharing it with my potential customer. I am able to login into facebook on my device (Samsung S8) running Android 7.0 and the behavior works as expected. Therefore my customer is not able to authenticate via facebook on his device. All other features of the app work accordingly and we are able to move development further, except this little issue with facebook authentication.

I thought you can give some hints on where I can look deeper to investigate and solve the issue. :slight_smile:

Thanks for sharing your help.
Happy coding!

Hi @gabrielmarchesan ,
The authentication issue may be related with the facebook app debug keyhash.So you have to collect the debug keyhash from your customer device and paste it inside the facebook app you have created on developer.facebook.com.

1 Like

Thanks @vibinflogesoft! We plan to give the first alpha version to around 10 customers. Do you think would be possible to generate one production hashkey and share the same apk to different customers so they can authenticate over facebook?

@gabrielmarchesan Ys.There are two type of keys.one is debug key and another is the release key.The release key hash will help you to authenticate from multiple devices release key generation

1 Like

Many thanks @vibinflogesoft! I will try this out!

After trying this out, I face the same problem. Here below what I did.

  1. created a release key
    keytool -genkey -v -keystore recruta.keystore -alias recruta -keyalg RSA -keysize 2048 -validity 10000
  2. copied the hash key into facebook developer website
  3. generated a release version of my app
    ionic cordova build --prod --release android
  4. signed the apk
    jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore recruta.keystore platforms/android/app/build/outputs/apk/release/app-release-unsigned.apk recruta
  5. zipaligned
    zipalign -f -v 4 platforms/android/app/build/outputs/apk/release/app-release-unsigned.apk Recruta.apk

the authentication works good on my device but not on my customer device.

I can send you the ‘apk’ privately if you would be willing to test it on your mobile.

Thanks again!

One more thing you have do is in your Google play console
1.Go to Release Management
2.select app signing in releasemanagement
3.You can see sha1 key in hex format.
4.Copy the sha1 in hex format and convert it in to base64 format.
5.Go to Facebook developer console
and add the key(after convert to base 64) in the settings—>basic–>key hashes
Please let me know if you have any doubts:smile:

1 Like

@vibinflogesoft, I would like to release my app only to some customers before making it available on play store… therefore I would like to be enable my customer to test the facebook login functionality as well. I still do not understand the reason why it works on my smartphone and not on his. We are installing from the same APK / which has been signed following the procedure previously described and we are getting different results. As authentication backend I am using firebase and it is working pretty well / on my mobile. If the app would not work on any device I could understand, but I do no see a logical explanation for that yet.

If you are trying to distribute the debug build to your some of the customers,the facebook login did not work for them.Because in case of debug build there will be seperate key hash for each of the device.In your case the debug keyhash is already generated and pasted it in your facebook developer console. Thats y the facebook login is working in your device.If you need to work the debug build on your customer device you should collect the keyhash from them.In the present situation the customer got an error screen while login to facebook.The error will be Invalid keyhash error(The keyhash does not match any stored keyhashes).So customer keyhash will shown in the error page.So collect the keyhash from your customer and paste on facebook developer console to fix the login issue.
Please let me know if you have any doubts

Hi @vibinflogesoft, I have still doubts regarding your recommendations.

Because in case of debug build there will be seperate key hash for each of the device

When I generate the key hash I do not provide any device ID, how this link is done?

If you need to work the debug build on your customer device you should collect the keyhash from them.

How can I generate keyhash specifically for their devices as I do not provide device ID information during the key hash generation process.

Thanks for being very supportive on that.

If your customers getting error will be just like this Invalid keyhash error
So they can view their key hash on their device screen while attempt to login.Try to append the keyhash on
facebook developer console to avoid the invalid key hash error.
please let me know if you have more doubts :smiley:

1 Like