2

I have the same code with the same p12 file (checked md5 sums), same account_email, and same scope working on a number of computers, but not working in Docker containers on any of the working computers. My code snippet is as follows:

with open(self.pkcs12_file_path, 'rb') as f:
    key = f.read()
    scope = ['https://www.googleapis.com/auth/bigquery',
             'https://www.googleapis.com/auth/cloud-platform']
    credentials = SignedJwtAssertionCredentials(self.account_email,
                                                    key, scope)
http = httplib2.Http()
self.http = credentials.authorize(self.http)
service = discovery.build('bigquery', 'v2', http=self.http)

Whenever I try this inside of a Docker container, I get oauth2client.client.AccessTokenRefreshError: invalid_grant at the discovery.build line. I'm thinking it might have something to do with needing to expose ports, but have no idea which I'd need to expose, or if that's the actual problem. Anyone have any ideas?

Eli
  • 36,793
  • 40
  • 144
  • 207

1 Answers1

3

This sounds like a clock issue. Google's OAuth access tokens are valid for one hour (Google refresh tokens are valid forever and you can use them to retrieve a new access token). Can you verify that the Docker container's clock is synced with the host machine (or set to your expected time zone?).

See: Will docker container auto sync time with the host machine?

Community
  • 1
  • 1
Michael Manoochehri
  • 7,931
  • 6
  • 33
  • 47
  • 1
    This is correct, but doesn't work on OS X. I was able to achieve the same by restarting the VM as its time crept away from system time. You can do that by doing `boot2docker restart`. I'd prefer to find a working version of the answer above so I don't have to worry about this again. I'll update here if I do. – Eli Sep 10 '14 at 20:37