How to Logout User Using Facebook Authentication Using Swift and iOS

How to logout user using Facebook authentication using Swift and iOS?

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.

Facebook SDK 4.0 IOS Swift Log a user out programmatically

Ok, here is the thing for anyone needs assistance.
I managed to log my users out using FBSDKLoginManager instance

Apparently and i don't know if is it documented or not FBSDKLoginManager watches

FBSDKAccessToken.currentAccessToken()

so

let loginManager = FBSDKLoginManager()
loginManager.logOut() // this is an instance function

Logs the user out, what i misunderstood that logOut is not a class function.

hope that helps someone!

How to Sign-out of Facebook Authentication in Firebase SDK for iOS

To sign a user in to Firebase Authentication through Facebook, they need to be signed in with Facebook, and with Firebase Authentication. If you want to then sign that user into Firebase Authentication with another provider, you only need to sign them out of Firebase Authentication.


Linking and unlinking providers serves another use-case. Say that you want to allow the user to sign in with their Google account, in addition to the Facebook account they're now signed in with.

In that case you can leave the user signed in, create separate authentication credentials for their Google account, and link the two providers together. From that moment on, no matter if the user signs in with their Facebook or with their Google credentials, they will be signed in to the same Firebase Authentication account.

Calling unlink after that allows you to unlink one of the providers from the account.


Update I think I understand now...

  1. You had a user that was signed in anonymously.
  2. Then you signed them in with a Facebook account.
  3. And next you signed them out of their Facebook account.
  4. Now you want to go back to the previous anonymous authentication account.

This is not possible. When you sign the user into Facebook, they are signed out of their previous account. And when a user is signed out of anonymous authentication, that account cannot be recovered.

If this is a normal use-case for your app, you'll have to link the Facebook account to the existing anonymous authentication account in step 2 above (instead of replacing it). If you do that, you can indeed unlink the Facebook account and get back to (only) the anonymous authentication provider.

How to Log out from Facebook or revoke login using Parse and Swift

Actually there is a difference between Revoking Login (letting people completely de-authorizing an app, or revoking login) and Logging out an user from his/her Facebook account:

Revoking Login

(you can check the Facebook documentation)

You can also let people completely de-authorize an app, or revoke login, by making a call to this Graph API endpoint:

DELETE /{user-id}/permissions

This request must be made with a valid user access token or an app access token for the current app. If the request is successful, your app receives a response of true. If the call is successful, any user access token for the person will be invalidated and they will have to log in again. Because you're de-authorizing your app, they will also have to grant access to your app as if they were logging in for the first time.

let facebookRequest: FBSDKGraphRequest! = FBSDKGraphRequest(graphPath: "/me/permissions", parameters: nil, HTTPMethod: "DELETE")

facebookRequest.startWithCompletionHandler { (connection: FBSDKGraphRequestConnection!, result: AnyObject!, error: NSError!) -> Void in

if(error == nil && result != nil){
println("Permission successfully revoked. This app will no longer post to Facebook on your behalf.")
println("result = \(result)")
} else {
if let error: NSError = error {
if let errorString = error.userInfo?["error"] as? String {
println("errorString variable equals: \(errorString)")
}
} else {
println("No value for error key")
}
}
}

Logging out an user form his/her Facebook account

If you have used Parse and the Facebook iOS SDK version >= 4.4.0 to sign up or log in a user via Facebook, and you do not want to de-authorize an app, or revoke login, but just want to log out the user from Facebook, then please use instead:

PFUser.logOut()

It will log out the user, delete the session on the Parse back-end side (do not forget to enable Parse revocable session via your Parse app settings), plus it will also delete the Facebook session written on the user device's disk.

I hope this answer will help you guys.

Logout from Facebook programmatically iOS

You have two methods to logout.
First, as suggested by Inder Kumar Rathore

FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
[loginManager logOut];

Second is by setting the currentAccessToken to nil

[FBSDKAccessToken setCurrentAccessToken:nil];

@cookiemonsta hope second method works for you.

How to completely Logout of Facebook SDK Auth in iOS App

I was able solve my this issue by changing the FBSDKLoginBehavior to web, see here: https://stackoverflow.com/a/44101753/1258525



Related Topics



Leave a reply



Submit