iOS Swift - How to use Facebook Sign Up and Login - ios

This is a very high level architectural question.
I want to use "Sign Up with Facebook" and "Log in with Facebook" in my iOS app.
Questions:
I find many tutorials for logging in with Facebook but I am not getting anything for Sign Up with Facebook, like a tutorial for "SignUp with Facebook".
How can I use Sign Up with Facebook in my app? As in, what will be the architecture? What do I need to send to my server? What I need to store about the user in my server's DB?
After checking Spotify's "SignUp with Facebook" my understanding is, when the user clicks on Sign up with Facebbok, he is still asked with Facebook login but the SignUp screen will get pre-filled with some basic information like phone, email, first and last name etc, which I can use on my app to sign up the user.
Next time when the user logs in using facebook I just validate if he has already signup or not
Am I thinking right? any corrections? feedback?

If you're using Facebook login for the sole purpose of it being an easy way to get your users to sign up/log in to your app, then your app will be rejected by Apple. You need to be using Facebook application features that go beyond just basic profile information and sharing.
I just went through this during the Apple App Store review process and think it's worth noting here. A little warning to those who think they will save time.

You will get the user's profile and info, plus a userId i think.
Then you can add the user's Facebook id as userID, Facebook email as username, and a very long pre-defined string as it's password.
This is totally secure as long as the very long pre-defined password is not public. Only your server (or your app) will have that and will put that as password when you log in.
The username will be the Facebook email, which is straight forward. And the userId in your database will be the Facebook id that you get from your login session.
All the data can be read from the FBSDKProfile, when login is successful.
Hope it helps :)
p.s. you can also use Digits by Twitter, it is an awesome SDK for signing in with phone verification.

Related

Facebook acoount login in webview

I want to know that is there any way to login my account in webview by picking username and password from textfields and load it in webview?
Basically I want to make an custom username and password fields. When user put fb name and password on it, it send request to facebook with username and password for login in webview for use facebook in webview. If username and password is correct then it save on NSUserDefaults for next time automatically login.
Please can anyone tell me how I can achieve functionality like this.
What you are asking is actually quit a common thing to do now days.
It is called social login, also known as social sign-in, that is a form of single sign-on using existing information from a social networking service such as Facebook, Twitter or Google+.
There is an official way to do this, you can check Facebook Documentation which guide you step-by-step on how to do this (pretty straight forward).
Basically you need to use Facebook Login Kit and they will handle the part where they present a webView and asking for credentials. You will get an access token which you can then store in the device (Keychain is much preferred from NSUserDefaults)
Note: The method you described in your question, where you ask the user for username and password store them and inject them to a web view is super not secure and is defiantly not the intent of Facebook API to use.

Handling Facebook as alternative login

I'm developing an iOS app with a server-side component. Users can create and login to accounts with an email/password combination. I'm also building in an option to alternatively login via Facebook. If the user logs in via Facebook I will need to create an account for them using the email we get from Facebook - but what do I do about the password? The server obviously requires a password to create an account. Should I use something like their Facebook user ID as a password (doesn't seem secure), do I force them to create a password? What's the standard practice here?
You can set a button text or alert saying "Use Facebook data for Registration".
After clicking on the button, you can redirect the user to the registration screen.
Fill up all the data with his facebook data then leave the password and confirm passwords blank to let him choose his password.
Trying to use his personal Facebook data as password may be the cause for rejection of your app on Appstore.

How to know user has already done Facebook login at iOS app

I am developing iOS App which use Facebook iOS SDK 4.
When user has already done Facebook login, by doing Facebook login the dialog which shows "user has already approved your app" had be displayed.
So, do not show the dialog. I want to know whether the user has already done Facebook login.
Anyone know the good way? I think accessToken is returned if user once had done Facebook login.
FBSDKAccessToken manage current logged user's accessToken.
According to official Facebook Login guide
"FBSDKAccessToken Represents the access token provided by a successful login. Most important, it provides a global +currentAccessToken to represent the currently logged in user."
The currentAccessToken is a convenient representation of the token of the current user and is used by other SDK components (like FBSDKLoginManager).
According to above you can check either user has valid accessToken or not and based on this you can track call login method otherwise just skip to next flow.
In Facebook the access tokens are per user so you can pass them around apps and they will work. In your case if you can ship an access token from another app you will be able to skip the next logging in and use the API normally.
However I think this this thread will help you.
Things are a little bit different with iOS cause I have done a facebook login on Android and got no such issues.

django-allauth and changing Facebook app ID

Does anybody know what will happen to my existing users when I will change Facebook app ID in allauth (socialauth) configuration?
Will "login with FB" try to create new django accounts or will it just log users in to existing ones (and obviously, asking via FB for permission)?
I'm in a situation where I have large amount of users signed up using FB but now I'm forced to create new FB app and switching to it.
Have checked it out. The answer is yes, users will fall into the signup flow instead of being logged in.
It's because Facebook assigns app-scoped ID to users. An app doesn't know user's original ID, it gets user's ID generated especially for this app. For this reason django-allauth won't recognize existing FB users (from previous FB app).

ios - multi facebook account on one device

I'm having an iOS app, need Facebook login to share something to wall. Everything is ok until I received new feedback from customer. Let me describe this case.
Apple have integrated Facebook into iOS system, user just needs to login via Setting, it is so easy for user. But my customer does not want to do that, they want user to login Facebook inside app and use it instead of Facebook of iOS system. Problem is here, there is a case: user has already logged in Facebook account A via iOS system, then user opens app and login Facebook inside app with other Facebook account B. After that, user shares a picture. Requiment is this picture should be shared on wall of Facebook account B (of app), but this picture appeared on wall of Facebook account A(of iOS system).
I just wonder do we have any solutions to resolve this case? Please give me any ideas you all have in mind after reading.
Thanks,
Ryan
I faced the same problem with Facebook SDK whenever a user login from any app using Facebook it change userid returned with the token which leads to share on the latest opened account.
if you open Facebook from a browser you will get this message from Facebook " we got confused please re-login "
so i took the same approach i saved user-id User(A) and whenever user share i check id coming with token if it changed i show " Facebook account changed please relogin " & i log all users out.
check this link may be helpful: https://www.facebook.com/help/community/question/?id=10205949056147843

Resources