0
我正在嘗試編寫一個基本的GAE應用程序來測試OpenId Connect。它在日誌中發生錯誤失敗:people()。get()中的「權限不足」。看起來這個程序要求OpenId證書,而不是OAuth(在登錄頁面的url中有一個重定向到https://accounts.google.com/o/openid2/auth,但這是隱含的,如何明確要求OAuth?很奇怪,因爲decorator.has_credentials()返回True這些OpenID憑證......在GAE上實現Google與openId Connect的連接
import logging
import webapp2
from apiclient.discovery import build
from oauth2client.appengine import OAuth2Decorator
from google.appengine.api import users
decorator = OAuth2Decorator(
client_id='123456789999.....googleusercontent.com',
client_secret='ABCDEF.........',
scope=['https://www.googleapis.com/auth/plus.login'])
service = build('plus', 'v1')
class MainHandler(webapp2.RequestHandler):
@decorator.oauth_aware
def get(self):
if decorator.has_credentials():
response =service.people().get(userId="me").execute(http=decorator.http())
# Write the profile data
self.response.write(unicode(response))
else:
url = decorator.authorize_url()
# Write a page explaining why authorization is needed,
# and provide the user with a link to the url to proceed.
# When the user authorizes, they get redirected back to this path,
# and has_credentials() returns True.
self.response.write('You must login : <a href="'+url+'">Go</a>')
app = webapp2.WSGIApplication([
('/', MainHandler),
(decorator.callback_path, decorator.callback_handler())],
debug=True)
看起來好像使用了OpenID 2.0而不是OAuth 2(請參閱授權屏幕上的消息) – frank 2015-04-01 20:55:38