Parse.com Is it possible to login using facebook while checking if the facebook user's email exists in a user in parse and if it does linking both?

时光毁灭记忆、已成空白 提交于 2019-12-10 13:53:33

问题


I'm having the following problem with the parse iOS SDK. In my app users can login using email (username)/password or facebook. When they use facebook the email (username) gets set automatically. But if the user logs in using email/password first and after logging out tries to login using facebook they get a duplicate account. My goal in this scenario is to link facebook to the previous account. Is there a way to check if the potential new user's email exist in parse database before creating a new account and if it exists then link both account? This way the user doesn't have to remember if they used facebook or email, they could use both seamlessly.

thanks.


回答1:


The basic logic you need here is as follows:

  1. Authenticate the user using Facebook
  2. Get the additional information you need--e.g., read email from the Facebook graph API, or (in my case) prompt the user for a phone number (which you cannot get from Facebook)
  3. Search the Parse user table for an account matching this piece of data (email address, phone number, etc.)
  4. If a match is found, and the user has authenticated against this identity*, link the accounts and login the user.
  5. If no match is found, create a new Parse account for the user, using the email/phone identity

It's outlined in more detail here: merge a user signed up by Facebook and already user signed up by email?. There's sample JS code but the idea should be the same for iOS.

*Pay close attention to what the Parser says in the last answer. If a Facebook user claims to own an email address or a phone number, you need to independently verify that they own that account (by e.g. sending an authorization link or code).




回答2:


You can do a simple query on the User table to see if a user already exists with the same username. If it does, you'll want to link the Facebook data to this account. Their docs outline how to do this with the SDK: https://parse.com/docs/ios_guide#fbusers-link/iOS




回答3:


It will link "user" with Facebook account easily.

NSArray *permissionsArray = @[ @"user_about_me", @"user_relationships", @"user_birthday", @"user_location"];
    [PFFacebookUtils linkUser:user permissions:permissionsArray block:^(BOOL succeeded, NSError *error) {
        //do anything
    }];


来源:https://stackoverflow.com/questions/19663807/parse-com-is-it-possible-to-login-using-facebook-while-checking-if-the-facebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!