CapacitorGoogleAuth icon indicating copy to clipboard operation
CapacitorGoogleAuth copied to clipboard

[Android] refresh expired token "I don't know how to refresh token on Android"

Open kamalessafi opened this issue 3 years ago • 8 comments

Greetings everyone ,

I happen to face an issue with android google auth , it's working all fine , I am able to sign in and get idtoken which I store in localstorage and sent it in the network . However when this idtoken expires , I call the GoogleAuth.refresh() which doesn't seem to work on android i'm getting this error message "I don't know how to refresh token on Android" . Albeit , it's working perfectly fine in the web where i'm able to get the refreshed token .

How are you guys able to refresh your tokens in android ? any advice ?

ps : I didn't test this in IOS yet .

I would highly appreciate your help :)

kamalessafi avatar Mar 07 '22 12:03 kamalessafi

Hello 👋 You're facing this problem because refresh isn't implemented for android. But it is implemented for web. What I suggest is for you to look into The silentSignin() method of Google Android Library and you can perhaps try implementing the refresh method yourself. That's what I'm currently experimenting with. If it seems to work, I'll try opening a pull request 🤷.

I have a very similar use case where I need to refresh the access_token so I can pass it to gapi.client. Similar to #175

Translucent504 avatar Mar 07 '22 13:03 Translucent504

Hello @Translucent504 , I hope you're doing fine :) .

Have you come up with a solution yet ?

I really need it badly !! my whole project is now on hold because of that problem :/ .

thanks in advance .

kamalessafi avatar Mar 24 '22 23:03 kamalessafi

@kamalessafi I overrided the refresh method, it looked something like this gist you'll probably need to clean it up a bit but it'll work in the current state by returning a refreshed access token in the auth object whenever you call the refresh method.

Translucent504 avatar Mar 27 '22 20:03 Translucent504

@Translucent504 thank you very much ^^ . I will try it and come back to you .

Thanks again

kamalessafi avatar Mar 30 '22 08:03 kamalessafi

Hello @Translucent504 I hope you're having a wonderful day ,

As for what you have posted as a solution didn't work for me :/ . I'm getting this error " com.google.android.gms.common.api.ApiException: 4: 4: " whenever I'm calling this method Task<GoogleSignInAccount> task = googleSignInClient.silentSignIn();

Any further help would be much appreciated ^^ .

kamalessafi avatar Apr 01 '22 09:04 kamalessafi

@kamalessafi I overrided the refresh method, it looked something like this gist you'll probably need to clean it up a bit but it'll work in the current state by returning a refreshed access token in the auth object whenever you call the refresh method.

wow, thanks, the refresh method worked for me

AnoOnion avatar Apr 26 '22 05:04 AnoOnion

ANy help here. I see a lot of people who try to find a solution to this.

Hello @Translucent504 I hope you're having a wonderful day ,

As for what you have posted as a solution didn't work for me :/ . I'm getting this error " com.google.android.gms.common.api.ApiException: 4: 4: " whenever I'm calling this method Task task = googleSignInClient.silentSignIn();

Any further help would be much appreciated ^^ .

I'm getting the same issue. Can you tell me how to resolve this?

iruthaya avatar Mar 03 '23 12:03 iruthaya