Silent sign in to retrieve token with GoogleApiClient

后端 未结 3 2118
难免孤独
难免孤独 2020-12-05 14:08

I am using \"Google Sign-In\" in my app. Hence I use the class GoogleApiClient to get the user email and the ID token that I need for my backend.

When the user signs

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-05 14:56

    To add to the two answers above by Isabella and Ola, if you're using the new sign in lib with Firebase:

    FirebaseAuth.getInstance().currentUser?.let{ 
        //create sign-in options the usual way
        val googleSignInClient = GoogleSignIn.getClient(context, gso)
        googleSignInClient.silentSignIn().addOnCompleteListener {
            val account: GoogleSignInAccount? = it.result
            //get user info from account object
        }
    }
    

    Also, this can be called from the UI thread. FirebaseAuth.getInstance().currentUser will always return the user object if you have signed in once before.

提交回复
热议问题