Python Google hybrid(openid+;oauth)协议不适用于127.0.0.1

Python Google hybrid(openid+;oauth)协议不适用于127.0.0.1,python,oauth,gmail,openid,google-openid,Python,Oauth,Gmail,Openid,Google Openid,我正在尝试实现google混合协议(oauth over openid)。 还有一个问题,谷歌没有要求oauth许可(尝试使用gmail),只有openid。 我在谷歌api控制台注册: Client ID for web applications Client ID: 248141267047.apps.googleusercontent.com Email address:248141267047@developer.gserviceaccount.com Client secret: R

我正在尝试实现google混合协议(oauth over openid)。 还有一个问题,谷歌没有要求oauth许可(尝试使用gmail),只有openid。 我在谷歌api控制台注册:

Client ID for web applications
Client ID: 248141267047.apps.googleusercontent.com
Email address:248141267047@developer.gserviceaccount.com
Client secret: 
Redirect URIs:  http://127.0.0.1:8000/oauth2callback
JavaScript origins:     http://127.0.0.1:8000
以下是生成openid url的python代码:

class OpenIDOAuthRequest(Extension):

    ns_alias = 'oauth'

    def __init__(self, consumer, scope, ns_uri=None):
        Extension.__init__(self)
        self.consumer = consumer
        self.scope = scope
        self.ns_uri = ns_uri or oauth_ns_uri

    def getExtensionArgs(self):
        return {
            'consumer': self.consumer,
            'scope': ' '.join(self.scope),
        }


def google():
        #define google openid url
        openid_session = {}
        openid_store = filestore.FileOpenIDStore('.')
        consumer = Consumer(openid_session, openid_store)
        openid = u"https://www.google.com/accounts/o8/id"
        URLS = {
            'ax_last': "http://axschema.org/namePerson/last",
            'ax_first': "http://axschema.org/namePerson/first",
            'ax_email': "http://axschema.org/contact/email",
            "country":"http://axschema.org/contact/country/home",
            "timezone":"http://axschema.org/pref/timezone",
            "language":"http://axschema.org/pref/language",
            "person":"http://axschema.org/namePerson",
        }
        #defining what fields we're going to get
        ax_request = ax.FetchRequest()
        for k,v in URLS.iteritems():
            ax_request.add(ax.AttrInfo(v, required = True))
        oa = OpenIDOAuthRequest("248141267047.apps.googleusercontent.com",["https://mail.google.com/",])
        try:
            authrequest = consumer.begin(openid)
        except DiscoveryFailure, e:
            print e
            print "some errror happened"
        else:
            authrequest.addExtension(ax_request)
            authrequest.addExtension(oa)



        redirecturl = authrequest.redirectURL("http://127.0.0.1:8000",
            return_to = "http://127.0.0.1:8000/oauth2callback",
            immediate=False)
        print redirecturl
它生成以下url:

https://accounts.google.com/o/openid2/auth?openid.assoc_handle=AMlYA9Vr6Biwp-rCAr4TLbf8CtItR-zr3bs0LT7oYQ3Pakg93ivCS_6C&openid.ax.mode=fetch_request&openid.ax.required=ext0,ext1,ext2,ext3,ext4,ext5,ext6&openid.ax.type.ext0=http://axschema.org/contact/email&openid.ax.type.ext1=http://axschema.org/namePerson&openid.ax.type.ext2=http://axschema.org/namePerson/first&openid.ax.type.ext3=http://axschema.org/pref/timezone&openid.ax.type.ext4=http://axschema.org/pref/language&openid.ax.type.ext5=http://axschema.org/contact/country/home&openid.ax.type.ext6=http://axschema.org/namePerson/last&openid.claimed_id=http://specs.openid.net/auth/2.0/identifier_select&openid.identity=http://specs.openid.net/auth/2.0/identifier_select&openid.mode=checkid_setup&openid.ns=http://specs.openid.net/auth/2.0&openid.ns.ax=http://openid.net/srv/ax/1.0&openid.ns.oauth=http://specs.openid.net/extensions/oauth/1.0&openid.oauth.consumer=248141267047.apps.googleusercontent.com&openid.oauth.scope=https://mail.google.com/&openid.realm=http://127.0.0.1:8000&openid.return_to=http://127.0.0.1:8000/oauth2callback?janrain_nonce%3D2012-05-01T22%253A50%253A33ZUW7vcj
它有所有必要的扩展。但是如果我访问这个网址,它不会要求我允许使用gmail。我还和sanebox.com上类似的url进行了比较。它的工作原理与预期一样,需要获得gmail的许可。但我并没有看到他们的url和我的url有什么本质区别。此外,我将我的url中的127.0.0.1替换为sanebox url,其他部分保持不变。而且。。。现在它正在申请gmail的许可。切换回127.0.0.1-停止询问。以下是sanebox url:

https://accounts.google.com/o/openid2/auth?openid.assoc_handle=AMlYA9UV4Ud714HHaFJ0fpItabA8v-zw0QuReEPcn61ilJzyFrFia5PO&openid.ax.mode=fetch_request&openid.ax.required=ext0,ext1,ext2,ext3,ext4,ext5,ext6&openid.ax.type.ext0=http://axschema.org/pref/timezone&openid.ax.type.ext1=http://axschema.org/contact/country/home&openid.ax.type.ext2=http://axschema.org/pref/language&openid.ax.type.ext3=http://axschema.org/namePerson/last&openid.ax.type.ext4=http://axschema.org/namePerson/first&openid.ax.type.ext5=http://axschema.org/namePerson&openid.ax.type.ext6=http://axschema.org/contact/email&openid.claimed_id=http://specs.openid.net/auth/2.0/identifier_select&openid.identity=http://specs.openid.net/auth/2.0/identifier_select&openid.mode=checkid_setup&openid.ns=http://specs.openid.net/auth/2.0&openid.ns.ax=http://openid.net/srv/ax/1.0&openid.ns.oauth=http://specs.openid.net/extensions/oauth/1.0&openid.ns.sreg=http://openid.net/extensions/sreg/1.1&openid.oauth.consumer=www.sanebox.com&openid.oauth.scope=https://mail.google.com/+http://www.google.com/m8/feeds&openid.realm=https://www.sanebox.com/&openid.return_to=https://www.sanebox.com/users?_method%3Dpost%26open_id_complete%3D1

那么我错过了什么?如果我在api控制台中注册了这个url,为什么它对127.0.0.1不起作用。而且它与openid配合得很好。在没有openid的情况下,oauth本身运行良好。但现在,当我尝试在openid上使用oauth时,它并没有要求我获得gmail的许可。

我已经运行了PHP、ASP和DOT NET代码,它们运行得非常好,因此确保python应用程序也能正确运行。您必须更改默认应用程序。首先运行他们提供的默认应用程序并尝试更改。如果默认应用程序不工作,那么to也可以向google打开一个bug报告。

我已经运行了PHP、ASP和DOT NET代码,它们运行得非常好,因此确保python应用程序也能正确运行。您必须更改默认应用程序。首先运行他们提供的默认应用程序并尝试更改。如果默认应用程序不起作用,to也可以向google打开一个bug报告。

问题只在于使用127.0.0.1运行它。最后,我将所需的域添加到主机文件中。python混合协议的默认应用程序不存在。只有im已经存在的openid库using@Aldarund它甚至在localhost上对我有效,即127.0.0.1。对于我发布的两个链接,你可以尝试打开它们。与localhost的链接不会要求你访问gmail,而与普通域的链接会这样做。链接之间的唯一区别是域。我注意到这两个,1。在发送请求的代码中,您的客户机密码在哪里。2.没有正确地定义这些勺子。其中是openid ns声明的\u id标识模式oauth作用域。请先阅读OpenID规范,然后尝试实现same1。客户端的秘密会在以后发生,而不是在我们生成url时发生。2.范围定义正确。。此代码100%正常工作。它现在在一个真实的站点上运行时没有任何错误。问题只是在127.0.0.1下运行它。最后,我将所需的域添加到主机文件中。python混合协议的默认应用程序不存在。只有im已经存在的openid库using@Aldarund它甚至在localhost上对我有效,即127.0.0.1。对于我发布的两个链接,你可以尝试打开它们。与localhost的链接不会要求你访问gmail,而与普通域的链接会这样做。链接之间的唯一区别是域。我注意到这两个,1。在发送请求的代码中,您的客户机密码在哪里。2.没有正确地定义这些勺子。其中是openid ns声明的\u id标识模式oauth作用域。请先阅读OpenID规范,然后尝试实现same1。客户端的秘密会在以后发生,而不是在我们生成url时发生。2.范围定义正确。。此代码100%正常工作。它现在在一个真实的站点上工作,没有任何错误。