Frage

I've got a Python program that interacts with Google APIs that authenticates via OAuth with the sample code that Google provides:

# Perform OAuth 2.0 authorization.
flow = oauth2client.client.flow_from_clientsecrets(
  parameters[self.PARAM_SECRETS], scope=self.GCE_SCOPE)
storage = oauth2client.file.Storage(LocalState.get_oauth2_storage_location(
  parameters[self.PARAM_KEYNAME]))
credentials = storage.get()

if credentials is None or credentials.invalid:
  credentials = oauth2client.tools.run(flow, storage)

# Build the service
return apiclient.discovery.build('compute', self.API_VERSION), credentials

However, whenever I do run this, it forces a browser to open and asks the user to click on a button to authenticate. This causes problems if the program runs on a machine without a local web server. I've seen this question, which seems to indicate that the problem can be solved by using --noauth_local_webserver, but it says that I have to rewrite my program to use gflags for argument processing, and my existing code already uses argparse.

Is there a way to authenticate users without forcing a browser to open, without having to rewrite my whole application to use gflags?

War es hilfreich?

Lösung

Well, it wont' help you today, but the dependency on gflags in the client library is being removed in the 1.2 release. The updated run() command now uses argparse, and in general there will be no dependency on any particular flags library in the core library. Unfortunately this doesn't solve the problem for you today. I'm hoping to get the 1.2 release out by the end of this month, but no guarantees.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top