Refresh token is always null, I plowed through the documentation and did serval experiments. But i could not get the refreshToken to renew the access token for offline use.
I'm using react-google-login to get my offline token. I assume this is correctly set up.
Just in case here's the setup:
<GoogleLogin
clientId="***"
buttonText="Login"
accessType="offline"
responseType="code"
scope={"https://www.googleapis.com/auth/calendar"}
onSuccess={responseGoogle}
onFailure={responseGoogle}
/>
But when I'm using the authorization code only an access token is returned that is valid for 3600 seconds. I can use the accessToken to access the api. But it seems the refresh token is not provided.
GoogleTokenResponse tokenResponse =
new GoogleAuthorizationCodeTokenRequest(
new NetHttpTransport(),
JacksonFactory.getDefaultInstance(),
"https://www.googleapis.com/oauth2/v4/token",
clientSecrets.getDetails().getClientId(),
clientSecrets.getDetails().getClientSecret(),
AUTH_CODE,
REDIRECT_URL)
.execute();
String refreshToken = tokenResponse.getRefreshToken();
String accessToken = tokenResponse.getAccessToken();
Any clue what is wrong?
It seems it was related to react-google-login... So i was looking at the wrong thing the whole time. Adding approvalPrompt="force"
and prompt='consent'
seems to fix it.
<GoogleLogin
clientId="***"
buttonText="Login"
accessType="offline"
responseType="code"
approvalPrompt="force"
prompt='consent'
scope={"https://www.googleapis.com/auth/calendar"}
onSuccess={responseGoogle}
onFailure={responseGoogle}
/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With