Closed octaflop closed 4 months ago
I am inclined not to add prompt=consent
because this changes the behavior of flow.run_local_server
, it will make flow.run_local_server
always show the consent page. https://developers.google.com/identity/openid-connect/openid-connect#authenticationuriparameters
Great point. I'm not sure how best to approach parameterizing or retrying in this edge case. Any thoughts would be helpful.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
try:
creds.refresh(Request())
# Save the credentials for the next run
with open(token_path, 'w') as token:
token.write(creds.to_json())
except google.auth.exceptions.RefreshError:
# fall back to run_local_server
pass
flow = InstalledAppFlow.from_client_secrets_file(
str(credentials_path), SCOPES)
url_args = {
'access_type': 'offline',
'prompt': 'consent'
}
try:
creds = flow.run_local_server(port=8080, open_browser=False, **url_args)
except MismatchingStateError:
print("State mismatch error during OAuth process. Trying again...")
creds = flow.run_local_server(port=8080, open_browser=False, **url_args)
# Save the credentials for the next run
with open(token_path, 'w') as token:
token.write(creds.to_json())
you may try this approach. If there is refresh token, just refresh an access token; if we cannot refresh or refresh fails due to expired refresh token, fall back to run_local_server with the url_args, this way you will get a new refresh_token.
Please reopen the issue if you have any questions. Thanks!
Thanks for stopping by to let us know something could be better!
PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.
Please run down the following list and make sure you've tried the usual "quick fixes":
If you are still having issues, please be sure to include as much information as possible:
Environment details
python --version
pip --version
google-auth-oauthlib
version:pip show google-auth-oauthlib
Steps to reproduce
refresh_token
.Code example
Stack trace
NA -- ValueError
Making sure to follow these steps will guarantee the quickest resolution possible.
Thanks!
Proposed fix (PR incoming)
add
prompt=consent
to theauthorization_url
as a default. As a current workaround I am finding this to work: