GoogleSignIn-iOS icon indicating copy to clipboard operation
GoogleSignIn-iOS copied to clipboard

Server auth token not refreshed after restorePreviousSignInWithCallback

Open daz001 opened this issue 3 years ago • 2 comments

Our app currently uses the server auth code to exchange for a token on the backend in order to get the google user id and from that the app specific user account. After we exchange this code on the backend, it is no longer valid and we cannot use it again.

On Android, our client will always give a new server auth code when the user does a silent sign in on app launch, but on iOS it seems to only provide the server auth code from the previous session. (via restorePreviousSignInWithCallback)

I was wondering if there is a way to force this to refresh so that we can get a valid server auth code (one that hasn't been used already)? Or am I perhaps thinking about the flow of this incorrectly?

Thank you

daz001 avatar Aug 19 '22 07:08 daz001

Facing the same problem. Do you have any solution or workaround already?

ziptwo avatar Aug 24 '22 13:08 ziptwo

Google Sign-In for iOS and macOS populates the serverAuthCode property of GIDGoogleUser with a new short-lived, one-time code after a successful sign-in flow. This is the point at which you should send the serverAuthCode value to your server. Your server can then exchange the serverAuthCode for ID, access, and refresh tokens. As it is a one-time code, you will not be able to exchange that serverAuthCode value again. If your server needs to use the ID or access tokens on an ongoing basis, it should use the refresh token from the initial exchange to obtain new ID and access tokens when they have expired. Please see our Server-side Access Guide for more detail on how to implement this flow.

Note that if you're only interested in using the ID token to authenticate with your backend, you don't need to use the Server-side Access flow and can simply use the ID token provided to your app via the authentication.idToken property of GIDGoogleUser. You can send this ID token to your backend for validation and then use it to authenticate the user. Please see our Authenticate with a Backend Server Guide for detail on this approach.

petea avatar Aug 31 '22 18:08 petea