Python 在GAE上使用openId connect实现Google connect

Python 在GAE上使用openId connect实现Google connect,python,google-app-engine,openid-connect,Python,Google App Engine,Openid Connect,我正在尝试编写一个基本的GAE应用程序来测试OpenId连接。它失败,日志中出现错误:people()上的“权限不足”。get()。似乎这个程序要求的是OpenId凭据而不是OAuth(在登录页面url中有一个重定向到。但这是隐式的。如何显式要求OAuth?这很奇怪,因为装饰程序。has_credentials()使用这些OpenId凭据返回True import logging import webapp2 from apiclient.discovery import build from

我正在尝试编写一个基本的GAE应用程序来测试OpenId连接。它失败,日志中出现错误:people()上的“权限不足”。get()。似乎这个程序要求的是OpenId凭据而不是OAuth(在登录页面url中有一个重定向到。但这是隐式的。如何显式要求OAuth?这很奇怪,因为装饰程序。has_credentials()使用这些OpenId凭据返回True

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)
导入日志
导入webapp2
从apiclient.discovery导入生成
从oauth2client.appengine导入OAuth2Decorator
从google.appengine.api导入用户
decorator=OAuth2Decorator(
客户端_id='12345678999…..googleusercontent.com',
客户_secret='ABCDEF………',
范围=['https://www.googleapis.com/auth/plus.login'])
服务=构建('plus','v1')
类MainHandler(webapp2.RequestHandler):
@decorator.oauth_-aware
def get(自我):
如果decorator.has_凭据():
response=service.people().get(userId=“me”).execute(http=decorator.http())
#写入配置文件数据
self.response.write(unicode(响应))
其他:
url=decorator.authorize_url()
#写一页解释为什么需要授权,
#并向用户提供指向url的链接以继续。
#当用户授权时,他们会被重定向回该路径,
#并且has_credentials()返回True。
self.response.write('您必须登录:')
app=webapp2.WSGIApplication([
(“/”,MainHandler),
(decorator.callback_路径,decorator.callback_处理程序())],
debug=True)

您必须在谷歌控制台中激活谷歌+API

API&Auth/API/Google+API


然后点击带有文本的按钮:“启用API”

似乎使用的是OpenID2.0,而不是OAuth2(授权屏幕上的cf消息)