spi*_*tan 6 google-app-engine oauth-2.0
我在google app-engine(http://spititan.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)
...
...
Run Code Online (Sandbox Code Playgroud)
这个工具对我来说很好用了很长一段时间,我需要每隔几天提供一次密码.我注意到OAuth2是当前推荐的身份验证方式,因此我设法学习使用它并按照文档编写以下代码段(http://code.google.com/p/google-api-python-client /维基/的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)
Run Code Online (Sandbox Code Playgroud)
我的理解是'client_id'和'client_secret'是在我注册应用程序时获得的,user_agent是一个自由格式字符串,问题是:我应该把什么放在'范围'中?我试过http://spititan.appspot.com/spititan但没有运气,有没有人有任何想法?
谢谢
尝试scope='https://www.googleapis.com/auth/appengine.admin'。我也曾在寻找 appengine 范围,并在这里找到了它:
如果您尝试执行除以管理员身份登录之外的其他操作,则此操作将不起作用。AFAIK GAE 支持 ClientLogin、OAuth 1.0 和 OpenID ATM。所以,没有 OAuth 2.0。我想知道他们什么时候会。
| 归档时间: |
|
| 查看次数: |
2258 次 |
| 最近记录: |