Facebook Login with another account from iOS app - ios

I'm developing an iOS app that integrates with Facebook SDK. When I make the login for the first time with my facebook account it takes the following steps:
Jump to safari web login
Insert my credentials
After that I authorize the permissions that are requested
And then I go to the main menu of my application.
When I press the logout button, I run the following code:
- (void)logout {
[FBSession.activeSession closeAndClearTokenInformation];
}
With this code I can invalidate the session and clear the access token information. However, when i try to login again, my application jumps to safari web login and my account appears already as logged in (next picture).
If I want to login with another Facebook account, i can't do it. In other words, I would like to follow the steps that I said earlier or have a mechanism like "Not you?" that Facebook official app provides.
Any idea that what I have to do?

You're still logged in through Safari. Log out there (or clear your cache).

wrong, happens when not logged in safari and FB app.

Related

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

How to log out of Facebook when using a custom login button, on iOS using FBSDKLoginKit?

I am implementing a custom login button in my iOS app, using the FBSDKLoginKit CocoaPod, version 4.8.0. I already have log in working, but I can't figure out how to log out of Facebook. I am already calling logOut on an instance of FBSDKLoginManager, but that only seems to clear the currentAccessToken value. When I tap my login button again, I see a screen that looks like this:
I want to be able to log in as a different Facebook user. How can I achieve this?
In the new version of the Facebook iOS SDK (4.6 and above, I think) the default behaviour of login uses Safari View Controller. So if you are logged into Safari and have already logged into your app using Facebook, it will not ask for your credentials again and show you that screen. If you want to log in as a different user, then you will need to log out of Facebook in Safari in which case the login dialog should ask for your credentials. Also, you can remove the app from your app settings and try to login in which case it will show you the permissions screen. This behaviour of the login dialog probably follows from the best practices where a logout from an app should not cause logout from Facebook itself.

Disconnecting Facebook from app on iOS6?

I'm using the latest Facebook iOS SDK, 3.1.1. I want to give users the option to "disconnect" our app from Facebook. I'm calling:
[[FBSession activeSession] closeAndClearTokenInformation];
That seems to work fine, but the next time I call
[FBSession openActiveSessionWithReadPermissions:allowLoginUI:completionHandler:handler];
it immediately gives me a token, without asking the user to login again. I would expect it to ask the user again to authenticate. If there's no Facebook account set up on the device, it works fine, because it opens the web browser where it tells the user they've already authenticated the app and shows the 'Okay' button. But if it is set up, it just silently gets the token again and so the user's "disconnecting" the app has no effect.
Is anyone else having this issue, and how are you handling it?
It doesn't ask again because the iOS SDK has given the Facebook SDK a valid access token. This is just how Apple designed their Facebook (and Twitter) frameworks. There's nothing you can do about it. Personally I think it's great. The user should only have to tell their phone once that they accept an app.
Also note that the cached token may have expired. The Facebook SDK at present doesn't fully handle the case where the iOS SDK gives it an expired token.
If you want to test then you can delete the Facebook account on your device and re-add it. That should clear the cached token.
Using:
- (void)openWithBehavior:(FBSessionLoginBehavior)behavior completionHandler:(FBSessionStateHandler)handler;
with FBSessionLoginBehaviorForcingWebView as the behaviour solved my problem. It opens the login modal box and forgets the user cookies.

Facebook iOS SDK and Safari based authentication issue

I have used latest FB SKD in my iOS app so users can use facebook account to login. Application open the FB app and comes back to my app perfectly fine. However, in some place in the app, i have to show/pull some people facebook page (safari based using WebView), but even user already used the Facebook account to login into my native ios app, but the page still ask user to login again and when they click login, it shows them the annoying FB username/pass page.
Is there anyway, that the FB safari based page can authenticate the user since it's already logged into my app using FB integration? do i have to include query or something. Please give me details how to solve this problem since i'm new in this..
thanks again for your help...
pic: https://www.dropbox.com/s/rjlptu7ufpcq3vl/fb.png
When the user switches to Facebook app to authenticate, it doesn't create a cookie for your UIWebView which is why it's asking to login again. Have the user authenticate inside the UIWebView without switching to the Facebook app.
What you're talking about also sounds like a similar thing that happens with Facebook dialogs not knowing about the current Facebook session.
If you authenticate your user via Facebook, try saying the Facebook object itself as an instance variable somewhere in memory so you can access it again (a property on a singleton controller, perhaps?).
Spawning dialogs from an authenticated Facebook object appears to let them use the dialog without reauthenticating iff you have a [FBSession activeSession]. So you'd also have to maintain an active FB session. But I'm not sure if this kind of solution will work since you didn't show specific code for how you're doing your web-based FB fetches.
This question might also prove helpful:
Implement Login with Facebook in iOS 5 and 6

can't switch users for FB connect on iOS

I have FB connect implemented in my app. After battling with the FB app installed on a user's phone, I finally had success forcing the standard FB dialog and bypassing the FB app
(see iOS: Connect to Facebook without leaving the app for authorization)
My new problem is that I cannot seem to switch FB users within the app. When I click the "Login with Facebook" button from within my app, it quickly brings up the FB dialog, dissappears, and always logs me back in with the previous user (meaning I have no way to switch FB users).
I've check both Safari and the FB app, and neither are logged in. Do I have to tell FB to log out the previous user before a new user/pass is prompted?
Thanks
Your implementation probably saves user's access token in NSUserDefaults. If it is so - you just need to delete it from NSUserDefaults any time there is a logout or you're switching users.
Also if needed you are able to deauthorize the user by making a DELETE graph API call to uid/permissions.
hope this helps

Resources