Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Google SignIn asks every time for permissions

I have implemented a Google SignIn with Firebase in my iOS app, following the Firebase guide. The problem is that every time I test the login, it always asks for permissions.
enter image description here

Here is the code of AppDelegate involved in Google SignIn:

class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
        // Override point for customization after application launch.
        FIRApp.configure()

        GIDSignIn.sharedInstance().clientID = FIRApp.defaultApp()?.options.clientID
        GIDSignIn.sharedInstance().delegate = self


        return true
    }

    func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
        return GIDSignIn.sharedInstance().handle(url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String, annotation: options[UIApplicationOpenURLOptionsKey.annotation])
    }

    func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {

        if let error = error {
            print(error.localizedDescription)
            return
        }


        print("Logged in with Google successfull")


        // ... Firebase authentication ...

    }
}

And here the code of View Controller with GIDSignInButton:

import UIKit

class IntroViewController: UIViewController, GIDSignInUIDelegate {


    @IBOutlet weak var signInButton: GIDSignInButton!


    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.

        GIDSignIn.sharedInstance().uiDelegate = self
        signInButton.style = .wide
    }


}

I've searched a lot on the web but found nothing... So, how can I prevent to ask for permission every time?

like image 789
alessionossa Avatar asked Aug 20 '16 09:08

alessionossa


People also ask

What is Firebase persistence?

firebase.auth.Auth.Persistence.SESSION. 'session' Indicates that the state will only persist in the current session or tab, and will be cleared when the tab or window in which the user authenticated is closed. Applies only to web apps.

How do I use Google authentication with Firebase?

In the Firebase console, open the Auth section. On the Sign in method tab, enable the Google sign-in method and click Save.

Which method will you call to logout a user from Firebase search in documentation?

If you'd like to sign the user out of their current authentication state, call the signOut method: import auth from '@react-native-firebase/auth'; auth() . signOut() .


1 Answers

I believe this is working as intended. The issue is that you're signing out the user when you're testing your app, and the Google Sign-in library makes the assumption that if a user has explicitly signed out of your app, it should ask that user for permission again before signing that user in.

If you don't explicitly sign out the user, both signIn() calls and signInSilently() calls should succeed without displaying any kind of sign-in screen.

like image 155
Todd Kerpelman Avatar answered Oct 07 '22 20:10

Todd Kerpelman