Skip to content

Instantly share code, notes, and snippets.

@wescpy
Created August 12, 2020 10:18
Show Gist options
  • Save wescpy/53d38da1e1ee32db91e5b9d8c95315fa to your computer and use it in GitHub Desktop.
Save wescpy/53d38da1e1ee32db91e5b9d8c95315fa to your computer and use it in GitHub Desktop.
"Unit tester" for Google Auth Library (Python) Bug 501
# https://github.com/googleapis/google-auth-library-python/issues/501
from __future__ import print_function
import os
from google.oauth2 import credentials
TOKENS = 'tokens.json' # OAuth2 token storage
if os.path.exists(TOKENS):
creds = credentials.Credentials.from_authorized_user_file(TOKENS)
if not (creds and creds.valid):
if creds and creds.expired and creds.refresh_token:
print('** Auto-refresh: got creds? [%s], valid? [%s], expired? [%s]' % (
bool(creds), creds.valid, creds.expired))
else:
print('** Re-run flow: creds [%s], valid? [%s], expired [%s]' % (
bool(creds), creds.valid, creds.expired))
else:
print('** "Valid" creds: creds [%s], valid? [%s], expired [%s]' % (
bool(creds), creds.valid, creds.expired))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment