diff --git a/src/auth/__init__.py b/src/auth/__init__.py index e4d0c34f..dde26bc1 100644 --- a/src/auth/__init__.py +++ b/src/auth/__init__.py @@ -1,10 +1,10 @@ """Authentication/Credentials general purpose and convenience methods.""" -from . import oauth +import transport from var import _FN_OAUTH2_TXT from var import GC_OAUTH2_TXT from var import GC_Values - +from . import oauth # TODO: Move logic that determines file name into this module. We should be able # to discover the file location without accessing a private member or waiting # for a global initialization. @@ -12,16 +12,19 @@ DEFAULT_OAUTH_STORAGE_FILE = _FN_OAUTH2_TXT def get_admin_credentials_filename(): - """Gets the name of the file that stores the admin account credentials.""" - # If the environment globals are loaded, use the set global value. It may have - # some custom name in it. Otherwise, just use the default name. - if GC_Values[GC_OAUTH2_TXT]: - return GC_Values[GC_OAUTH2_TXT] - else: + """Gets the name of the file that stores the admin account credentials.""" + # If the environment globals are loaded, use the set global value. It may have + # some custom name in it. Otherwise, just use the default name. + if GC_Values[GC_OAUTH2_TXT]: + return GC_Values[GC_OAUTH2_TXT] return DEFAULT_OAUTH_STORAGE_FILE def get_admin_credentials(): - """Gets oauth.Credentials that are authenticated as the domain's admin user.""" - credential_file = get_admin_credentials_filename() - return oauth.Credentials.from_credentials_file(credential_file) + """Gets oauth.Credentials that are authenticated as the domain's admin user.""" + credential_file = get_admin_credentials_filename() + creds = oauth.Credentials.from_credentials_file(credential_file) + if creds.expired: + request = transport.create_request() + creds.refresh(request) + return creds diff --git a/src/gam.py b/src/gam.py index ebf7bf3e..8d9562e4 100755 --- a/src/gam.py +++ b/src/gam.py @@ -7817,9 +7817,6 @@ def doCreateResoldCustomer(): def _getValueFromOAuth(field, credentials=None): if not credentials: credentials = auth.get_admin_credentials() - if credentials.expired: - request = transport.create_request() - credentials.refresh(request) return credentials.get_token_value(field) def doGetMemberInfo():