Authentication and login to my app with Facebook iOS SDK - ios

I am using the Facebook iOS SDK to allow quick sign-up of users in my app. Here is the flow:
User taps "Login with Facebook" button
Taken to Facebook app or Safari for login
Redirected back to my app
Show Sign-up for with pre-filled fields from FBGraphUser object
User creates account using data from Facebook
After they created an account, is it possible to authenticate with Facebook, and let them login to my app without having to enter the username and password they just created? How would the flow of that work?
Seems like I should be able to do the following:
User taps on "Login with Facebook" button
Authenticate with Facebook SDK
Return to app, and make a call to server, checking to see if there is a username matching the Facebook email
Allow the user into the app with no password, since they have authenticated with Facebook and have an account in our system.
Is this the correct way to do it?

That is very close. However, it is not enough to just check that the email/username is valid. It is strongly recommended to validate the token directly with Facebook as well.
See Use Facebook authentication token in API for a very similar concept and the Facebook docs about verifying token: https://developers.facebook.com/docs/graph-api/securing-requests.

Related

swift facebook sdk logout function not working

I am working on app that needs facebook to login. In other means we are using facebook authentication in our app along with in app login screen.
So now at very first, I was able to login using my facebook account. When i first tried it, I have to provide both user name and my password to get login using my facebook account credentials.
Now after that I want to logOut from facebook account whenever user hit Logout button from our app. Here is what I am doing
AccessToken.current = nil
Profile.current = nil
LoginManager().logOut()
but it is not actually working. When I press again to login back, now I never see that screen where I gave facebook account credentials. its mean LogOut() function is not working.
Please help me this is weird behavior from facebook sdk

iOS 9 Facebook SDK Multiple Users

I have followed the iOS 9 Facebook SDK instruction to the letter and facebook login works great, but the app can only support one Facebook user.
I want to support multiple users, but seem to be stuck with whatever user I first logged in with through the Facebook SDK.
Scenario 1:
If I delete my app from the list of allowed apps on facebook website (in settings) and then activate the Facebook login (provided by the Facebook SDK) in my app, rather than allowing me to login in as a different user it asks if I want to "Continue" loging in as the last user that used the facebook login from my App. If I confirm it reauthorizes the app on my facebook account and logs me in as the last user that logged in. Here is the dialog I get when trying to login in after deleting the app from my facebook account.
Scenario 2: The app has been authorized on my facebook account. I chose to log out in my app. I call the facebook logout as shown
FBSDKLoginManager().logOut()
When I go to log in again using the facebook login button (provided by the Facebook sdk), rather than present me with a new facebook login screen it gives me the following:
I don't want to confirm login as the last user. Hitting cancel does nothing. Hitting confirm logs me in again as the last user.
Question: How do I force the facebook sdk to clear out the last users facebook credentials?
Thanks in advance!!
Logout, than set loginBehavior = FBSDKLoginBehaviorWeb when you login.
Reset Facebook Token Reference - Facebook SDK 4.0
When you set login behaviour to web:
loginManager.loginBehavior = .web
with every login you can auth with new credentials

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.

Can we get email Id from Facebook application?

Can an application check if anybody is logged into Facebook application in mobile ,if logged in get the user email Id from that and use it in their application?
To get a logged in users email address, you would have to authenticate with the API and the user would have to approve you using the Oauth workflow.
You can display a customized login / connect button using the Facebook API but if I recall correctly, that is an iframe that is embedded in your page, and you never see the email from that.
tldr; No. You need to authenticate using the Oauth workflow and have the user grant you permission.
First you have to authenticate user and then you can get logged in user profile information. For that you have to use Facebook API. Please check below link.
https://developers.facebook.com/docs/facebook-login/ios/v2.2

iOS7, Sign in and post to twitter without Twitter App/ Add new ACAccount

So I'm trying to integrate twitter with the app I'm working on. The flow I'm looking for is one in which the user is prompted to enter his twitter username and password just once, and then anytime the user wants to post to twitter he can do so by entering text into a textfield and clicking a "send" button - no other hurdles.
I know how to accomplish this if the user already has the twitter app installed with an associated account - you can retrieve the account form the ACAccountStore. But what do you do when the user does NOT have the twitter app installed/no twitter account in ACAccountStore? Is there a way to add a new ACAccount using the username and password I have the user enter in-app?
You can then use the twitter framework for setting the account with in the app or you can force the user directly from with in the app to goto setting and set up an account for twitter..

Resources