10

I am creating an app that a person can signup with facebook, twitter or email. When looking for friends it can link his facebook, twitter accounts.

The problem is that if a person is already linked with facebook or twitter, I cannot link it with the other account, so every time the person needs to look for friends it need to login again.

Is there a way I can have both authdata to the same user so when the user links both twitter and facebook, it will show the friends without need of login again?

Thanks!

jarlh
  • 42,561
  • 8
  • 45
  • 63
ElvisBoss
  • 199
  • 3
  • 12
  • See https://stackoverflow.com/questions/16228930/parse-com-pfuser-linking-twitter-and-facebook-account – Russell Oct 29 '15 at 20:55

4 Answers4

3

Great question. This was a hard one for me to find the answer to as well. Unfortunately, the Parse User table that has default User fields that are unique and requires there to be only one User per account. I doesn't matter how they are logging in (via Facebook, Twitter, Email, ect), there can be only one username passwordof email field ect. You can watch them talk about it and why it's that way here in their Ask Parse Anything.

I know it's not ideal for developers who what to give the user an option on the platform they want to sign in on. If you add both the user would have to remember if their account was set-up through Facebook or Twitter in your case.

However, if you wanted to keep/link the Facebook and Twitter aspects to your project you may be able to pull the users email (assuming they use the same one for both their Facebook and Twitter accounts) from Facebook and Twitter and do the authentication through their email address.

Hope that helps. Cheers!

garrettmac
  • 8,417
  • 3
  • 41
  • 60
2

The answer is a big NO. Since, Parse.com has only one User class for One Application and in that User class we only have one -authData- (Authentication Data). Whenever a user signs in with social network credentials, that data shall be used for the session. That AuthData consists of maximum of 1 type.

taruntejae
  • 410
  • 4
  • 14
2

Had the same issue, plus I also wanted the Google+ login. What I did was to create an Account object that contains the following field:

  • Provider: String - Twitter, Facebook, Google, …
  • uniqueId: String - Contains a Twitter ID, Facebook ID, etc.
  • User: Pointer - Contains the user associated with this ID

Then I created a script that browse all the users and export their authData into several Account entries. I also added an afterSave hook on _User to migrate the new users data.

Now the hard part… Since Parse gives us no hook for a social login, I had to handle everything manually on Cloud Code. The idea is to use the SDK from Facebook and Twitter to get the user's account ID and access token. Then you send those data to a loginFromFacebook/LoginFromTwitter cloud function, and control that the Facebook/Twitter ID matches the access token (by doing a request to the Facebook's Graph API for example). Once you know the user id you have is correct, you need to check if it exists in Account. If yes you return (with response.success) the session token of the Parse user associated to this id (the Account.user field) and use User.become on the client to finish login the user. If not, you need to create a new user, add en entry in Account, and return the new user's session token (+ doing the User.become on the client).

Now, thanks to the Account table, you can easily link/unlink users by simply changing the associated user ID in the Account table. You can also easily check for Facebook friends (if you request the permission).

3lil636wm
  • 7,580
  • 3
  • 24
  • 26
0

I do not think that this can be done. Since parse.com does not allow for multiple linking on the same user. Also, I would highly doubt that a workaround would be possible because of the security on Twitter and Facebook for linking accounts. Therefore, I would say that there is no way to have the same user link to both Twitter and Facebook in Parse.

So, you are stuck with either having to get the user login multiple times to find friends (which probably wouldn't be the end of the world but is far from ideal) or just picking one service. I personally would just use Facebook because it isn't followers and following and is actually a mutual friend. That is just my opinion though as I do not know the nature of your application.

Anthony Dito
  • 3,610
  • 3
  • 29
  • 56