So here is my problem. I log in to my application, then log out of my application, but when I try to log in again, I get the screen in the link below.
Login Screen
As you can see, I don't get the opportunity to login with another user, which is what is intended.
What I tried to do was logout and then clear all the cookies in the logout using these following methods:
#IBAction func logout(sender: AnyObject) {
//Logged out here
let loginManager = FBSDKLoginManager()
loginManager.logOut()
//This is one method I tried
let appDomain = NSBundle.mainBundle().bundleIdentifier!
NSUserDefaults.standardUserDefaults().removePersistentDomainForName(appDomain)
//This is another method I tried
for key in NSUserDefaults.standardUserDefaults().dictionaryRepresentation().keys {
NSUserDefaults.standardUserDefaults().removeObjectForKey(key)
}
//And this is the last method I tried
var cookie: NSHTTPCookie
var storage: NSHTTPCookieStorage = NSHTTPCookieStorage.sharedHTTPCookieStorage()
for cookie in storage.cookies! {
var domainName: String = cookie.domain
var domainRange: Range = domainName.rangeOfString("facebook")
if domainRange.length > 0 {
storage.deleteCookie(cookie)
}
}
}
None of these seemed to solve my problem. The app is in "Development" mode in the Facebook Dev account so it might have something to do with this, but not totally sure. Does someone have any experience with this and know the solution to our problem, as shown in the image above.
The whole goal of Facebook login is to allow quick, seamless login into your Facebook account without having to re-enter credentials.
To achieve this, the Facebook SDK tries to leverage credentials that are already stored on the device, which may include:
login information from the Facebook app
cookies related to Facebook login in Safari (directly or via the SFSafariViewController)
system Facebook accounts
When you logout, you actually only have the Facebook SDK forget the credentials within the app (it clears the token). When you login again, it acts like the first time you did, and if it finds an existing user, it will use that (the Facebook SDK makes the — usually valid — assumption that there is a single person using the device, and they have a single Facebook account).
The current "favorite" path for the Facebook SDK (though that varies with SDK versions, iOS versions, and possibly other parameters) is SFSafariViewController, which shares cookies with Safari, not with your app.
If you want the user to completely log out on the device, they would then have to use the log out link within Facebook in Safari (or an SFSafariViewController).
If you want to do so programatically, you may open the following URL in Safari or an SFSafariViewController:
https://www.facebook.com/logout.php?next=[YourAppURL]&access_token=[ValidAccessToken]
You'll have to use a custom URL scheme to return to your app/exit the SFSafariViewController, though.
If you, as a user, want to see permissions request from Facebook again, you should remove the app from user's profile on Facebook.
When you are at settings screen, find your app and hit the cross button
Related
I've tried searching around but I can't find the answer to my question.
I'm playing around with this application from github:
https://github.com/Yalantis/Koloda/tree/master/Example
I'm using it because I'm doing a project which will use the tile based swiping from this application.
I'm also using firebase. So far, I can add users to my database, so the app and firebase are connected.
I also want users to register/login using facebook.
I have connected my app to facebook and a user can come in and successfully login using facebook authentication.
The problem I am having is logging out.
When I click on the logout button, I want the user to be completely logged out. So there is a logout method that comes with the facebook SDK called logout.
Here are the relevant parts of my code.
import FBSDKLoginKit
#IBAction func handleLogout(sender: AnyObject) {
facebookLogin.logOut()
print("loggedout")
}
So when I click on logout and then click on login again I get this page:
http://imgur.com/owi3zZn
I do not want the user to stay authorized after they have clicked on the logout button. How do I make it so that when I click on the logout button, the user is completely logged out from Facebook and then when they click on the login button they have to re-enter their username/password?
I've tried looking around the webz but can't find a solution to my problem, although I'm sure it's something pretty simple, I hope!
Thank you for your help and sorry if the formatting is poor.
If you to make the user log out from the app itself programmatically, you can check the following code.
let loginView : LoginManager = LoginManager()
loginView.loginBehavior = FBSDKLoginBehavior.Web
This will open the Facebook login popup in your app in which users can login into your app.
And for the logout, you can call:
let manager = LoginManager()
manager.logOut()
This will log out the user from the facebook in the app, after this if you call login method of SDK you will see the login popup again
If you want to clear the profile and token, also call the below code with logout.
FBSDKAccessToken.setCurrentAccessToken(nil)
FBSDKProfile.setCurrentProfile(nil)
When you call the logOut, the user is logged out of your app. As far as logging them out of Facebook, I don't think you can do that, nor would Facebook allow it. The first time a user authorizes you app through Facebook, Facebook adds your app to the list of apps that they are authorized with (they can access that page through Facebook.com). When they logOut and logIn again, they will see the page that you posted a picture of because they already authorized it. The only way for them to reauthorize themselves is to delete the app from their Facebook app page and log in to your app again.
The way the current Facebook SDK handles this seems like a security vulnerability to me. If I borrow a friends iPad and login to an app with Facebook when I logout I should be completely logged out of the app and the SFSafariViewController it used to authenticate me. Whereas right now it still remembers me in the SFSafariViewController using cookies.
To properly logout the user from both the Facebook SDK and SFSafariViewController I do the following:
let fbLoginManager = LoginManager()
fbLoginManager.logOut()
let cookies = HTTPCookieStorage.shared
let facebookCookies = cookies.cookies(for: URL(string: "https://facebook.com/")!)
for cookie in facebookCookies! {
cookies.deleteCookie(cookie )
}
I really dislike this solution but it's the best I've been able to come up with.
User Dan L has the correct answer, in one of my comments he wrote:
Oh, I see what you mean. If you go into the safari app, you can go Facebook.com and logout of your account, login to a different account, and go back into your app. The safari extension the pops up when you call the Facebook login should show the new user that logged in!
This is exactly what I needed. Thank you Dan L.
from your comments i can see what you want.
you can just reset your simulator's content and settings :
Click simulator / Reset Content and Settings
I'm working on an iOS app that will be used by multiple users. For example, this will be installed at a kiosk, so multiple people will interact with it and then be able to login to Facebook and share content.
I'm able to login/logout with Facebook credentials in the application; however, when I go to login the next time... the embedded popup safari browser remembers the previous logged in user and says "You have already authorized ". What's proper way to clear the user, so that the safari browser does not remember the last user? I have searched everywhere and people suggest clearing cookies with var httpCookie:NSHTTPCookieStorage=NSHTTPCookieStorage.sharedHTTPCookieStorage()... but this returns 0 items. Any help or guidance would be much appreciated!
This should do the trick:
let storage = NSHTTPCookieStorage.sharedHTTPCookieStorage()
for cookie in storage.cookies! {
storage.deleteCookie(cookie)
}
I've tried searching around but I can't find the answer to my question.
I'm playing around with this application from github:
https://github.com/Yalantis/Koloda/tree/master/Example
I'm using it because I'm doing a project which will use the tile based swiping from this application.
I'm also using firebase. So far, I can add users to my database, so the app and firebase are connected.
I also want users to register/login using facebook.
I have connected my app to facebook and a user can come in and successfully login using facebook authentication.
The problem I am having is logging out.
When I click on the logout button, I want the user to be completely logged out. So there is a logout method that comes with the facebook SDK called logout.
Here are the relevant parts of my code.
import FBSDKLoginKit
#IBAction func handleLogout(sender: AnyObject) {
facebookLogin.logOut()
print("loggedout")
}
So when I click on logout and then click on login again I get this page:
http://imgur.com/owi3zZn
I do not want the user to stay authorized after they have clicked on the logout button. How do I make it so that when I click on the logout button, the user is completely logged out from Facebook and then when they click on the login button they have to re-enter their username/password?
I've tried looking around the webz but can't find a solution to my problem, although I'm sure it's something pretty simple, I hope!
Thank you for your help and sorry if the formatting is poor.
If you to make the user log out from the app itself programmatically, you can check the following code.
let loginView : LoginManager = LoginManager()
loginView.loginBehavior = FBSDKLoginBehavior.Web
This will open the Facebook login popup in your app in which users can login into your app.
And for the logout, you can call:
let manager = LoginManager()
manager.logOut()
This will log out the user from the facebook in the app, after this if you call login method of SDK you will see the login popup again
If you want to clear the profile and token, also call the below code with logout.
FBSDKAccessToken.setCurrentAccessToken(nil)
FBSDKProfile.setCurrentProfile(nil)
When you call the logOut, the user is logged out of your app. As far as logging them out of Facebook, I don't think you can do that, nor would Facebook allow it. The first time a user authorizes you app through Facebook, Facebook adds your app to the list of apps that they are authorized with (they can access that page through Facebook.com). When they logOut and logIn again, they will see the page that you posted a picture of because they already authorized it. The only way for them to reauthorize themselves is to delete the app from their Facebook app page and log in to your app again.
The way the current Facebook SDK handles this seems like a security vulnerability to me. If I borrow a friends iPad and login to an app with Facebook when I logout I should be completely logged out of the app and the SFSafariViewController it used to authenticate me. Whereas right now it still remembers me in the SFSafariViewController using cookies.
To properly logout the user from both the Facebook SDK and SFSafariViewController I do the following:
let fbLoginManager = LoginManager()
fbLoginManager.logOut()
let cookies = HTTPCookieStorage.shared
let facebookCookies = cookies.cookies(for: URL(string: "https://facebook.com/")!)
for cookie in facebookCookies! {
cookies.deleteCookie(cookie )
}
I really dislike this solution but it's the best I've been able to come up with.
User Dan L has the correct answer, in one of my comments he wrote:
Oh, I see what you mean. If you go into the safari app, you can go Facebook.com and logout of your account, login to a different account, and go back into your app. The safari extension the pops up when you call the Facebook login should show the new user that logged in!
This is exactly what I needed. Thank you Dan L.
from your comments i can see what you want.
you can just reset your simulator's content and settings :
Click simulator / Reset Content and Settings
I'm testing Facebook single sign on in the following scenarios
When an account is logged in via Settings\Facebook
When an account is logged in via Safari
When an account is logged in via the local app.
The last test, when the Facebook app is installed and has valid credentials, never seems to work.
The only options that seem to work is when Safari is logged out OR the settings\Facebook system isn't logged in either.
I don't want to cause the user to ever enter a password, especially into a Web browser (or something that looks like one).
Question
How do I get iOS SDK to authenticate using the installed, working Facebook app?
Research
I've tested all forms of Facebook authentication, where I set the loginButton to all loginBehaviors, and even a null parameter
loginButton = new LoginButton (new CGRect (48, 0, 218, 46)) {
// LoginBehavior =
// LoginBehavior.Browser // safari
// LoginBehavior.Native // safari
// LoginBehavior.Web // popup (doesn't feel secure)
//LoginBehavior.SystemAccount // SYSTEM, if fail then Safari... ignore app
};
Have you whitelisted Facebook apps in the info.plist file?
From Facebook Docs (https://developers.facebook.com/docs/ios/ios9):
If you use any of the Facebook dialogs (e.g., Login, Share, App
Invites, etc.) that can perform an app switch to Facebook apps, you
will need to update your application's plist to handle the changes to
canOpenURL described in
https://developer.apple.com/videos/wwdc/2015/?id=703.
I have a requirement to integrate facebook login in my iOS app, everything is fine according to the instructions given at the below link
https://developers.facebook.com/docs/ios/getting-started
However I have a scenario where I need to implement a conditional redirection for facebook, such as
if (User is Not Logged In)
{
Then redirect to The Installed Facebook application and Get the details of user from the Facebook Application
}
else
{
// If user is logged in
Then Open a Webview to Enter Login
Credentials
}
my problem is due to placing the URL Schemes under URL types in info.plist I can open it in only one manner across the application,
Either I place The facebookId URL schema as the First Object and open the Installed facebook app, or Place it as second Object to open a Webview
Is there any way possible where I can check if the user is logged in then place the URL Schema at the top and not make it fallback to webview, but if not I Change it to be the first object in URL Types so it open the installed Facebook Application for Login