Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we suppress Google from automatically trying to refresh on expired tokens? #2339

Open
nick-catalist opened this issue Feb 16, 2024 · 1 comment
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@nick-catalist
Copy link

nick-catalist commented Feb 16, 2024

We need to capture user's Google Auth Tokens to securely store on our own side. I want to prevent Google from attempting to refresh the token on requests itself, since then it refreshes the token, and we are never informed of this.

Currently, we work around this by not providing the refresh token when initializing the client, and then catching the RefreshError that gets emitted and then POSTing a request to refresh the token ourselves.

However, I suspect this is causing problems sometimes, e.g. when we refresh the token and a Google client that has the old token makes a call and attempts a refresh internally, this might be causing Google to invalidate all active tokens via automatic reuse detection.

I wonder if there is just a way that we can tell the Google python API client to not attempt a refresh at all, but instead just return the 401 response/error so that we can handle refreshes ourselves?

For context, we are initializing our clients like so:

google_credentials = google.oauth2.credentials.Credentials(token=access_token)
service = googleapiclient.discovery.build("calendar", "v3", credentials=google_credentials)

And an example call we're making where we'd like it to NOT try a refresh:

self.service.events()
                .list(
                    calendarId="primary",
                    timeMin=time_min,
                    timeMax=time_max,
                    orderBy="startTime",
                    singleEvents=True,
                    maxResults=results_per_page,
                    pageToken=page_token,
                )
                .execute()
@nick-catalist nick-catalist changed the title Can we suppress Google from automatically trying to refresh on auth failure? Can we suppress Google from automatically trying to refresh on expired tokens? Feb 16, 2024
@parthea parthea added the type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. label Mar 28, 2024
@derwaro
Copy link

derwaro commented Apr 22, 2024

I'm in the same situation.
How long can the library go on auto-refreshing using the refresh-token? I implemented some logic as of now that should trigger, when the refresh does fail eventually, but how can I be sure of that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

3 participants