在Google App Engine中寻找与python混合的openid + oauth混合的好示例/模板

如何解决在Google App Engine中寻找与python混合的openid + oauth混合的好示例/模板

| 我已经分别实现了oauth和openid(即使用OpenId登录,使用OAuth对Google Data API进行了单独授权),并希望将它们结合在一起。 目前,我的app.yaml中包含以下内容
- url: /_ah/login_required
  script: main.py

- url: .*
  script: main.py
  login: required
然后,在main.py中,我有: (为清楚起见,删除了进口)
def getClient():
    client =  gdata.calendar.service.CalendarService()
    consumer_key = \'my-app.appspot.com\'
    consumer_secret = \'consumersecret\'
    client.SetoAuthInputParameters(
        gdata.auth.OAuthSignatureMethod.HMAC_SHA1,consumer_key=consumer_key,consumer_secret=consumer_secret)
    gdata.alt.appengine.run_on_appengine(client)
    return client

class OAuthOne(webapp.RequestHandler):
    def get(self):
        client = getClient()
        request_token = client.FetchOAuthRequestToken(oauth_callback=\'http://my-app.appspot.com/oauth2\')
        client.SetoAuthToken(request_token)
        auth_url = client.GenerateOAuthAuthorizationURL()
        self.redirect( auth_url )

class OAuthTwo(webapp.RequestHandler):
    def get(self):
        client = getClient()
        token_from_url = gdata.auth.OAuthTokenFromUrl(self.request.uri) 
        if not token_from_url:
            self.redirect(\'/oauth\')
        else:
            client.SetoAuthToken(token_from_url)
            oauth_verifier = self.request.get(\'oauth_verifier\',default_value=\'\')
            client.UpgradetoOAuthAccesstoken(oauth_verifier=oauth_verifier)
            self.redirect(\'/\')

class MainPage(webapp.RequestHandler):

    def get(self):
        self.user = users.get_current_user()
        self.template_values = {}
        if self.user:
            # do calendar api stuff here
            self.template_file = \'templates/index.html\'
        else:
            self.template_file = \'templates/denied.html\'

        path = os.path.join(os.path.dirname(__file__),self.template_file)
        self.response.out.write( template.render(path,self.template_values) )

application = webapp.WsgiApplication(
                                 [(\'/oauth\',OAuthOne),(\'/oauth2\',OAuthTwo),(\'/_ah/login_required\',OpenIDHandler),(\'/\',MainPage)],debug=True)

def main():
    run_wsgi_app(application)

if __name__ == \"__main__\":
    main()
同样在main.py中,来自http://code.google.com/googleapps/marketplace/tutorial_python_gae.html
class OpenIDHandler(webapp.RequestHandler):
    def get(self):
        \"\"\"Begins the OpenID flow and begins Google Apps discovery for the supplied domain.\"\"\"
        login_url = users.create_login_url(dest_url=\'http://my-app.appspot.com/\',_auth_domain=None,federated_identity=\'gmail.com\')
        self.redirect( login_url )
至于混合协议,这里有一个PHP示例,这里有一个Java示例,但是我找不到适用于python的任何东西。 我假设魔术的开始将需要在我的OpenIDHandler中发生,并且我需要使用除
users.create_login_url()
之外的其他东西。 Google的文档在这里告诉我,我需要“创建执行发现和发出身份验证请求的机制。”和“向身份验证请求添加OAuth功能”(此处提供更多文档),但据我所知告诉,而不是怎么做。至少不是Python。 此页面上有一个原始HTTP请求的示例,该请求稍低一些
https://www.google.com/accounts/o8/id
?openid.ns=http://specs.openid.net/auth/2.0
&openid.claimed_id=http://specs.openid.net/auth/2.0/identifier_select
&openid.identity=http://specs.openid.net/auth/2.0/identifier_select
&openid.return_to=http://www.example.com/checkauth
&openid.realm=http://www.example.com
&openid.assoc_handle=ABSmpf6DNMw
&openid.mode=checkid_setup
&openid.ns.oauth=http://specs.openid.net/extensions/oauth/1.0
&openid.oauth.consumer=www.example.com
&openid.oauth.scope=http://docs.google.com/Feeds/+http://spreadsheets.google.com/Feeds/
但是我不确定如何使用它。 因此,除了使它成为最佳实践的光辉典范之外,我真的需要知道如何“向身份验证请求添加OAuth功能”。     

解决方法

        在这里将OAuth库用于appengine https://github.com/mikeknapp/AppEngine-OAuth-Library查看该项目中的sample.py文件。     

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?