Dan6erbond / sk-auth

Authentication library for use with SvelteKit featuring built-in OAuth providers and zero restriction customization!
MIT License
578 stars 70 forks source link

Refresh tokens to obtain new access tokens #67

Closed HalfdanJ closed 2 years ago

HalfdanJ commented 2 years ago

I'm trying to understand how to use the library with short lived access tokens (the google provider). How can I access the refresh_token, and thereby obtain new access_tokens? I need the access token to call googleapi calls, but after an hour it expires, and I need to login again to obtain new tokens.

HalfdanJ commented 2 years ago

Turned out the normal step of revoking access to my app didn't prompt new refresh tokens. I had to add following configuration:

new GoogleOAuth2Provider({
  clientId: import.meta.env.VITE_GOOGLE_OAUTH_CLIENT_ID,
  clientSecret: import.meta.env.VITE_GOOGLE_OAUTH_CLIENT_SECRET,
  authorizationParams: {
    prompt: 'consent',
    access_type: 'offline',
    response_type: 'code',
  },
  [...]
}