How to get Google refresh token with knpuniversity/oauth2-client-bundle?

  google-oauth2, oauth-2.0, refresh-token, symfony

I use knpuniversity/oauth2-client-bundle and league/oauth2-google to connect users in my Symfony 4 web app using a “Sign in with Google” feature. I followed this tuto. I registered my app in Google.

I set access_type: offline in the knpu.oauth2.client.google configuration (config/packages/knpu_oauth2_client.yaml file)

I try to get the user refresh token in my GoogleAuthenticator::getUser(LeagueOAuth2ClientTokenAccessToken $credentials) method (which extends KnpUOAuth2ClientBundleSecurityAuthenticatorSocialAuthenticator).

Unfortunately, $credentials->getRefreshToken() always returns null.

Why don’t I get the user refresh token ?

Source: Symfony Questions

LEAVE A COMMENT