0

I'm writing a basic app that prints out projects in Google's Cloud Resources Manager using this method: https://cloud.google.com/resource-manager/reference/rest/v1/projects/list

Yesterday it worked but I revoked the token and the code doesn't prompt to re-authorize.

from googleapiclient import discovery from oauth2client.client import GoogleCredentials

credentials = GoogleCredentials.get_application_default()

service = discovery.build('cloudresourcemanager', 'v1', credentials=credentials)

projects = service.projects() request = projects.list() while request is not None:

    response = request.execute()

    for project in response['projects']:
        print project
    request = projects.list_next(previous_request=request, previous_response=response)

File "oauth2client/client.py", line 834, in _do_refresh_request raise HttpAccessTokenRefreshError(error_msg, status=resp.status) oauth2client.client.HttpAccessTokenRefreshError: invalid_grant: Token has been revoked.

I think there's a way to tell the client to check if the token is valid and pop the user out to a browser if not, but can't seem to get the code to do it. Any help appreciated ;)

Michael
  • 116
  • 1
  • 5

2 Answers2

2

Since this code uses application default credentials, the gcloud command is how I get a new token:

gcloud beta auth application-default login

Although it would be nice if there was a way to do this in code in the event the token is revoked again.

Michael
  • 116
  • 1
  • 5
0

Suddenly yesterday we faced a similar issue in Google OAuth2 connection from gerrit code review. So just wanted to share this as it might be related to you. Refer this github issue & its commit made for gerrit-oauth-provider

Jayaprakash
  • 703
  • 6
  • 15
  • Thanks, I appreciate the response. I'm not sure it's related though. Mine stopped working when a security tool (CloudLock) revoked the OAuth token from my Google account. The client library is assuming the token is still valid, but it's not, and needs to get a new one. – Michael Sep 29 '16 at 05:08