6

我有一个托管在 google app-engine (http://spittan.appspot.com) 上的应用程序。我还有一个命令行工具可以通过 ClientLogin 访问该应用程序。代码片段如下:

138   # get an AuthToken from Google accounts
139   auth_uri = 'https://www.google.com/accounts/ClientLogin'
140   authreq_data = urllib.parse.urlencode({ "Email":   email_address,
141                                     "Passwd":  password,
142                                     "service": "ah",
143                                     "source":  appname,
144                                     "accountType": "HOSTED_OR_GOOGLE" })
145   request = urllib.request.Request(auth_uri, data=authreq_data)
146   response = opener.open(request)
147   response_body = str(response.read(), 'utf-8')
148   response_dict = dict(x.split("=") for x in response_body.split("\n") if x)
149   return response_dict["Auth"]

...
...

112   # Send the auth token to the AppEngine to login
113   continue_location = "http://localhost/"
114   args = {"continue": continue_location, "auth": auth_token}
115   host = "spititan.appspot.com" % appname 
116   url = "https://spititan/_ah/login?%s" % urllib.parse.urlencode(args)
...
...

这个工具对我来说很好用了很长一段时间,但我需要每隔几天提供一次密码。我注意到 OAuth2 是当前推荐的身份验证方式,因此我设法学习使用它并按照文档(http://code.google.com/p/google-api-python-client)编写以下代码片段/wiki/OAuth2):

 59   storage = oauth2client.file.Storage(
 60       os.path.join(FLAGS.data_dir, 'confidential.dat'))
 61 
 62   credentials = storage.get()
 63 
 64   if credentials is None or credentials.invalid == True:
 65     flow = oauth2client.client.OAuth2WebServerFlow(
 66         client_id='<xxxxx>',
 67         client_secret='<xxxxx>',
 68         scope='<xxxxx>',
 69         user_agent='<xxxx>')
 70 
 71     credentials = oauth2client.tools.run(flow, storage)
 72 
 73   http = httplib2.Http(cache=".cache")
 74   http = credentials.authorize(http)

我的理解是'client_id'和'client_secret'是在我注册应用程序时获取的,user_agent是一个自由格式的字符串,问题是:我应该在'范围'中放什么?我试过http://spittan.appspot.com/spittan但没有运气,有人知道吗?

谢谢

4

1 回答 1

0

试试scope='https://www.googleapis.com/auth/appengine.admin'。我曾经也在寻找 appengine 范围,并在这里找到了它:

http://code.google.com/p/googleappengine/source/browse/trunk/python/google/appengine/tools/appcfg.py#143

如果您尝试以管理员身份登录以外的其他操作,这将不起作用。AFAIK GAE 支持 ClientLogin、OAuth 1.0 和 OpenID ATM。所以,没有 OAuth 2.0。我想知道他们什么时候会。

于 2012-04-08T13:41:08.427 回答