[GH-ISSUE #2558] Google Provider refresh token #17881

Closed
opened 2026-04-15 16:14:06 -05:00 by GiteaMirror · 8 comments
Owner

Originally created by @Mateleo on GitHub (May 6, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/2558

Is this suited for github?

  • Yes, this is suited for github

I need to have the refresh token.
Better Auth does not provide refresh token for the Google Provider

Describe the solution you'd like

Gather the refresh token (like Discord Provider does)

Describe alternatives you've considered

I may have to do it myself

Additional context

No response

Originally created by @Mateleo on GitHub (May 6, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/2558 ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. I need to have the refresh token. Better Auth does not provide refresh token for the Google Provider ### Describe the solution you'd like Gather the refresh token (like Discord Provider does) ### Describe alternatives you've considered I may have to do it myself ### Additional context _No response_
GiteaMirror added the locked label 2026-04-15 16:14:06 -05:00
Author
Owner

@zpg6 commented on GitHub (May 7, 2025):

Be sure to set accessType to offline to enable refresh tokens.

google: {
    clientId: process.env.GOOGLE_CLIENT_ID,
    clientSecret: process.env.GOOGLE_CLIENT_SECRET,
    accessType: "offline", // Required to enable refresh tokens
}

You can find out more about this in Google's guide for Using OAuth 2.0 for Web Server Applications.

Update

Tested myself and this does not save the refresh token as expected. The accessType is added to the authorizationUrl, but still null in the database.

<!-- gh-comment-id:2858312585 --> @zpg6 commented on GitHub (May 7, 2025): Be sure to set `accessType` to `offline` to enable refresh tokens. ``` google: { clientId: process.env.GOOGLE_CLIENT_ID, clientSecret: process.env.GOOGLE_CLIENT_SECRET, accessType: "offline", // Required to enable refresh tokens } ``` You can find out more about this in Google's guide for [Using OAuth 2.0 for Web Server Applications](https://developers.google.com/identity/protocols/oauth2/web-server#creatingclient). ## Update Tested myself and this does not save the refresh token as expected. The accessType is added to the authorizationUrl, but still `null` in the database.
Author
Owner

@Mateleo commented on GitHub (May 16, 2025):

@zpg6 Nice try :(

<!-- gh-comment-id:2887567416 --> @Mateleo commented on GitHub (May 16, 2025): @zpg6 Nice try :(
Author
Owner

@thisIsAdityaAtMagna commented on GitHub (May 21, 2025):

Same issue, cannot refresh the access token w/o Refresh Token.
One absurd workaround is to set the session expiry shorter that the google access token expiry that's the only way to make sure user always have a working access token.

<!-- gh-comment-id:2896124905 --> @thisIsAdityaAtMagna commented on GitHub (May 21, 2025): Same issue, cannot refresh the access token w/o Refresh Token. One absurd workaround is to set the session expiry shorter that the google access token expiry that's the only way to make sure user always have a working access token.
Author
Owner

@thisIsAditya commented on GitHub (May 21, 2025):

Updates on this:

	socialProviders: {
		google: {
			clientId: GOOGLE_CLIENT_ID,
			clientSecret: GOOGLE_CLIENT_SECRET,
			scope: [
			],
			accessType: "offline",
			prompt: "consent"
		}
	},

Using given code does get the refresh token @Mateleo but the down side being, the user have to consent with each login. Which is a terrible User Experience.

There is no way to check for expiry of refresh token to assert the prompt type, like:

let prompt;
if(accout.refresh_token === null || account.refreshTokenExpiresAt < now()) {
    prompt = "consent"
}
<!-- gh-comment-id:2897846904 --> @thisIsAditya commented on GitHub (May 21, 2025): Updates on this: ``` socialProviders: { google: { clientId: GOOGLE_CLIENT_ID, clientSecret: GOOGLE_CLIENT_SECRET, scope: [ ], accessType: "offline", prompt: "consent" } }, ``` Using given code does get the refresh token @Mateleo but the down side being, the user have to consent with each login. Which is a terrible User Experience. There is no way to check for expiry of refresh token to assert the prompt type, like: ``` let prompt; if(accout.refresh_token === null || account.refreshTokenExpiresAt < now()) { prompt = "consent" } ```
Author
Owner

@Mateleo commented on GitHub (May 22, 2025):

@thisIsAditya Thks, but it's not a viable solution for sure

<!-- gh-comment-id:2901190499 --> @Mateleo commented on GitHub (May 22, 2025): @thisIsAditya Thks, but it's not a viable solution for sure
Author
Owner

@jaimewukb commented on GitHub (May 30, 2025):

Has anyone managed to resolve this? I added accessType: "offline" but the refresh token still doesn't update in my db

<!-- gh-comment-id:2920988780 --> @jaimewukb commented on GitHub (May 30, 2025): Has anyone managed to resolve this? I added accessType: "offline" but the refresh token still doesn't update in my db
Author
Owner

@thisIsAditya commented on GitHub (Jun 16, 2025):

@jaimewukb use prompt: "consent" along with accesstype offline.
But it's not viable at all. Really bad UX

<!-- gh-comment-id:2977751894 --> @thisIsAditya commented on GitHub (Jun 16, 2025): @jaimewukb use prompt: "consent" along with accesstype offline. But it's not viable at all. Really bad UX
Author
Owner

@ping-maxwell commented on GitHub (Jul 8, 2025):

Hey guys - nothing you can really do much about this. It's by design from google.
I'm going to close this issue if there is nothing else.
Ping me if you have any questions or want me to reopen it for something.

<!-- gh-comment-id:3049498516 --> @ping-maxwell commented on GitHub (Jul 8, 2025): Hey guys - nothing you can really do much about this. It's by design from google. I'm going to close this issue if there is nothing else. Ping me if you have any questions or want me to reopen it for something.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#17881