Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access token in Google Sign In is null #52

Open
wanek21 opened this issue Sep 23, 2024 · 1 comment
Open

Access token in Google Sign In is null #52

wanek21 opened this issue Sep 23, 2024 · 1 comment

Comments

@wanek21
Copy link

wanek21 commented Sep 23, 2024

Sometimes, I can't retrieve the email from googleTokenId on my backend (explained here) so I need to send an additional request with the accessToken on the backend. The issue is that onGoogleSignInResult returns a null accessToken in the GoogleUser object:

GoogleButtonUiContainer(onGoogleSignInResult = { googleUser ->
        if (googleUser != null) {
                val idToken = googleUser.idToken
                println("id token: $idToken")
                println("access token: ${googleUser.accessToken}") // this is always null
            }
        }) {}

I checked the source code and found this lines (source):

GoogleUser(
    idToken = googleIdTokenCredential.idToken,
    accessToken = null,
    displayName = googleIdTokenCredential.displayName ?: "",
    profilePicUrl = googleIdTokenCredential.profilePictureUri?.toString()
)

So, the accessToken is always null. Perhaps I'm looking in the wrong place, and there’s another way to obtain the accessToken. Could you take a look at this, please?

P.S.: Thanks for the great library!

@mirzemehdi
Copy link
Owner

@wanek21 So here's what I found so far:

in ios side Google Sign in returns accessToken directly. But in android, looks like it doesn't provide accessToken directly, it provides idToken, which then you can use in the server side to get email. But as you pointed out sometimes this doesn't work.

You can check this one too: https://stackoverflow.com/questions/78911767/android-kotlin-google-credential-manager-get-access-token

What I found so far that, instead of using Google One Tap Sign in, we can use Google Legacy Sign in, and using requestServerAuthCode() would return serverAuthCode which can be changed in the server side with accessToken. Not sure exact details however.

Do you have any example code that you used in android side (not KMP) for solving this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants