0

I'm using the Google client API library for Python. My code is running on an Ubuntu 14.04LTS server.

I have a working Google Compute project, were I created and downloaded a OAuth2.0 token to my server.

I'm trying to write a script that does the following:

  1. Automatically (with no user interaction) authenticate to Google Compute engine.
  2. create a new VM and then perform more actions...

My basic problem is using the OAuth2.0 authentication. It required user approval on a javascript supporting browser, and I want to do it automatically, on my server.

Using my code on my desktop works. A browser page pops up requiring my approval. On my server, I get the following message:

we have detected that your javascript is disabled in your browser

The code segment I use for authentication is:

# authenticate using the OAuth token 
client_secret = os.path.join(
 os.path.dirname(__file__),
 self._oauth_token_path)
# set up a Flow object for the authentication 
flow = client.flow_from_clientsecrets(
 client_secret,
 scope=scope,
 message=tools.message_if_missing(client_secret))
# open credential storage path 
credential_storage = file.Storage(self._credential_storage_path)
credentials = credential_storage.get()
# get credentails if necessary 
if credentials is None or credentials.invalid:
credentials = tools.run_flow(flow, credential_storage, flags)

I read about service account access as a replacement of the regular OAuth2.0 authentication. Does any one know if that's the best way to go? any thoughts on how to do it better?

jub0bs
67.3k27 gold badges198 silver badges200 bronze badges
asked Nov 29, 2015 at 7:57

1 Answer 1

1

OAuth 2.0 requires user approval and is not the method to go for if you want to run your code/scripts automatically. Service accounts are more suitable for this and are supported by the API (https://cloud.google.com/compute/docs/authentication#tools) You create a service account + key in the developer console and use both to authenticate your application.

answered Nov 30, 2015 at 13:16
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.