-
-
Notifications
You must be signed in to change notification settings - Fork 887
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
GoogleSignIn.getTokens() not returning new tokens in android #926
Comments
I am also experiencing this issue |
@devksingh4 @Infinity-Intellect did you guys find a solution for this? |
@sammysium I unfortunately did not find a solution to this. Are many other people also experiencing this issue? |
I think you need to call |
I thought of it but it returns wrote SignInRequired.
…On Sun, Jan 3, 2021, 1:42 AM Miloš Rosić ***@***.***> wrote:
I think you need to call signInSilently()
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#926 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ALF7AKG3NV4AUXGT33SJB4LSX6VMTANCNFSM4TDXYANA>
.
|
I am not completely sure about this, but I think solution should be to check whether JWT expired, if it is then just call |
That is what I have been doing, and it is still returning the expired tokens. |
Have you tried a GoogleSignin.configure({
forceCodeForRefreshToken: true,
}); |
Yes..it is set to true.
…On Mon, Jan 18, 2021, 6:41 AM Firmansyah ***@***.***> wrote:
Have you tried a forceCodeForRefreshToken property? Like:
GoogleSignin.configure({
forceCodeForRefreshToken: true,});
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#926 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ALF7AKHHGF6W3Q4Y756HAELS2O3YFANCNFSM4TDXYANA>
.
|
May I see your configuration? |
So upon further investigation, it looks like that GoogleSignin.getCurrentUser() will not always return null when no user is signed in. I tested this by signing all Google users out of the device and then calling GoogleSignin.getCurrentUser() - it did not return null, but instead returned the old user's data, presumably stored from before. My current workaround is to just query my backend API server to see if it can use the given ID token - if it can't, then user sign in needs to be forced again. It looks like this library employs some caching beyond what is native? |
FYI, I was having the same issue, and fixed by using the following code: import { GoogleSignin, statusCodes } from "@react-native-google-signin/google-signin";
// Seems that without `signInSilently()`, `getCurrentUser()` sometimes return `null` (?)
try {
await GoogleSignin.signInSilently();
} catch (error) {
if (error.code !== statusCodes.SIGN_IN_REQUIRED) {
throw error;
}
}
// Remove cached access_token, since `GoogleSignin.getTokens()` may return expired tokens
const oldUser = await GoogleSignin.getCurrentUser();
if (oldUser) {
const oldTokens = await GoogleSignin.getTokens();
if (oldTokens.accessToken) {
console.log('Removing old access token', {oldTokens});
await GoogleSignin.clearCachedAccessToken(oldTokens.accessToken);
}
}
await GoogleSignin.signOut(); // https://github.com/react-native-google-signin/google-signin/issues/1022#issuecomment-1115847835 (credits: #792 (comment)) |
Please help me I get access from a google user but I need a refresh token I can get please give me proper any docs or solutions in react native |
any solutions? |
This is what worked for me:
|
Once my token expires, I first call
GoogleSignIn.clearCachedAccessToken(accessToken)
and then callGoogleSignIn.getTokens()
. However, I do not get a set of fresh tokens, rather I am provided with the same expired set of tokens.Steps to Reproduce
Below is my refresh code function :-
Expected Behavior
I expected to receive a new set of tokens, that has an expiry time 1 hour from the time getTokens() is called.
Actual Behavior
I receive the old set of tokens, that have already expired.
Environment
@react-native-community/google-signin: ^4.0.3
The text was updated successfully, but these errors were encountered: