0
votes

I have implemented a google oauth signup. I can request the tokens with the code provided when the user clicks login via google.

However, the tokens only include the refresh token the very first time that the user signs up/logs in. All later attempts to get tokens with the auth code only return an access token, but not a refresh token. I have to manually revoke the app permission in the user's google settings in order to force a new permission prompt which provides me with a new refresh token.

Is there some way to request a refresh token with the auth code? I.e. not just during the first login.

1
Hi Chris, can you please post a snippet of your code?mary
Why do you want to get a refresh token each time? Refresh tokens are meant to be stored and used to exchange for access tokens.user2705223
@user2705223 I dont want it each time. But I want to be able to explicitly request it in case some error occured during the first time and it did not get saved.Chris
Ah, in that case, you should set prompt=consent as you've discovereduser2705223

1 Answers

1
votes

I found the solution. The refresh token is only sent with the response when the consent screen is shown to the user. This only happens during the first login and once the user grants the permission the screen will not be shown anymore.

However, it is possible to force show the consent screen, which results in the refresh_token being sent.

You can do this by adding

prompt=consent

to the oauth url. or if you use the php api you can set it like this:

$client->setApprovalPrompt('consent');