Start a new topic

Facebook relogin | Android

Dear Kinvey team.


We are experiencing problem with Facebook.

Business idea is when user is able to connect Facebook account to the existing user and save all the data from the table.


It is two cases:


Case 1: Cannot associate a Facebook user with a User

https://devcenter.kinvey.com/android/guides/users#usingsocialidentities


Pre-conditions: 

1) Use different emails for registration and for facebook sign up. 

2) Be sure, that these emails are not presented in Kinvey Users' database.


Steps to reproduce

1) Register new user using https://devcenter.kinvey.com/android/guides/users#signup with the first email (e.g. test@test.com)

2) Make call https://devcenter.kinvey.com/android/guides/users#facebook with your facebook account (should be another email)

3) Check logs


Actual result:

com.kinvey.java.KinveyException: 

REASON: Attempting to login when a user is already logged in

FIX: call `UserStore.logout(myClient, kinveyClientCallback)` first -or- check `myClient.isUserLoggedIn()` before attempting to login again

EXPLANATION: Only one user can be active at a time, and logging in a new user will replace the current user which might not be intended

User cannot be logged in because this facebook email does not exist in database yet.


Expected result: User associated with Facebook User successfully.


-----------------------------------------------------------------------


Case 2: Cannot associate a Facebook user with a User

https://devcenter.kinvey.com/android/guides/users#usingsocialidentities


Pre-conditions: 

1) Use the same emails for registration and for facebook sign up.

2) Be sure, that these emails are not presented in Kinvey Users' database.


Steps to reproduce

1) Register new user using https://devcenter.kinvey.com/android/guides/users#signup 

2) Make call https://devcenter.kinvey.com/android/guides/users#logout

3) Make call https://devcenter.kinvey.com/android/guides/users#facebook (your FB account should have the same email that was used in step 1)

4) Make call https://devcenter.kinvey.com/android/guides/users#UserClass (BTW documentation is incorrect - no such method)

new UserStore().save(mKinveyClient, new KinveyClientCallback<User>() }) 

5) Check logs


Actual result:

New user was created but cannot be updated because of exception

com.kinvey.java.core.KinveyJsonResponseException: UserAlreadyExists

This username is already taken. Please retry your request with a different username


Expected result: User associated with Facebook User successfully.


Could ypu please help us with this solution?


Hi Michael,


Please accept our apologies for the late reply.


The current Android SDK version (3.0.4) does not support connecting a Facebook account (or multiple social identity accounts) to a single User. It supports registering multiple social identities account  - when using Login with Social Identities (loginFacebook, loginGoogle, loginTwitter, etc.), the method will create a separate new users with the login credentials provided. I can see that the documentation is misleading and have notified the responsible team for this to be fixed.


As a workaround, to associate a Facebook account to an existing Kinvey user, as this is not supported by the Android SDK out of the box, you may update the properties of an existing user, adding a "_socialIdentity" property to it. The steps to follow would be:

1. Create a Kinvey user in the backend (if such exist, login with that user)

2. Use Facebook SDK to login the user and get its Facebook access token. 

3. Update the Kinvey user by adding a "_socialIdentity" property to it:


{
    "_socialIdentity":
    {
        "facebook":
        {
            "access_token": "facebook_access_token_here",
            "id": "facebook_id_here",
            "name": "facebook_client_name_here"
        }
    }
}

 

Thus, the user would have a property "_socialIdentity.facebook" which would later be used when you use the loginFacebook() method. The same would be used to connect a twitter account for example - you would add "_socialIdentity.twitter" property similar to the facebook one. Here you can see the REST API endpoints available when using social identities.


Let me know if this workaround has helped in your case.

Internal Update: MLIBZ-2072

Login or Signup to post a comment