Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Sign Out of Google After Being Authenticated

So my app has the option to sign in with Google. Upon clicking the button that Google provides, a web view opens and has the user input their credentials. After allowing the app to access their information the app then signs the user in and changes the SignInViewController to the TabBarController (where they can now interact accordingly).

When the user presses a Signout button they are directed to the login screen as one would expect. But the odd thing is, if the user presses the google button again they are automatically signed in with no further authentication at all and no option to remove their account. Is their a way to clear the google account credentials as to protect the users from accidental theft?

Sign in function:

func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!, withError error: NSError!) {     if let error = error {         print(error.localizedDescription)         return     }     let authentication = user.authentication     let credential = FIRGoogleAuthProvider.credentialWithIDToken(authentication.idToken, accessToken: authentication.accessToken)     FIRAuth.auth()?.signInWithCredential(credential) { (user, error) in         // ...         SignInViewController().signedIn(user)     }     // ... } 

Sign out function:

func signOutOverride() {     do {         try! FIRAuth.auth()!.signOut()         CredentialState.sharedInstance.signedIn = false         // Set the view to the login screen after signing out         let storyboard = UIStoryboard(name: "SignIn", bundle: nil)         let loginVC = storyboard.instantiateViewControllerWithIdentifier("SignInVC") as! SignInViewController         let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate         appDelegate.window?.rootViewController = loginVC     } catch let signOutError as NSError {         print ("Error signing out: \(signOutError)")     } } 
like image 452
About7Deaths Avatar asked Jun 21 '16 05:06

About7Deaths


People also ask

How do I sign out of Google Authenticator?

Open your Google Account. In the "Security" section, select 2-Step Verification. You might need to sign in. Select Turn off.

Why does Google keep asking me to authenticate?

The error may simply be a sign-in issue, which sometimes occurs when the Play Store is updated. The first trick is to go into your phone's main Settings menu and then Accounts & sync and simply remove the Google account that is getting the "authentication is required" error.

Do I need to sign out of Google every time?

If you log into a Google account using private browsing, closing the browser window will automatically log you out, so you'll need to log in again the next time you use the browser.

How do I sign out of Apple after authentication?

As stated before; Apple does not have a sign out function available to use for the "Sign in with Apple". Currently, the user must go into the Settings application and revoke permission.


1 Answers

Swift

try GIDSignIn.sharedInstance().signOut()

objective - c

[[GIDSignIn sharedInstance] signOut]; 
like image 65
Rahul Patel Avatar answered Sep 30 '22 03:09

Rahul Patel