简体   繁体   中英

Google hybrid ( openid + oauth) protocol doesn`t work for 127.0.0.1

Im trying to implement google hybrid protocol (oauth over openid). And the problem that google doesn`t ask for oauth permission( trying with gmail), only openid. I registered at google api console:

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

Here is my python code for generating openid url:

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

It generates following 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

And it has all necessary extensions. But if i go to this url it doesnt ask me permission for gmail. Also i was comparing to similar url from sanebox.com. And it works as expected, asking for permission for gmail. But i didnt see any essential difference why their url is working and mine is not. Futhermore, i replaced 127.0.0.1 in my url to sanebox urls, and left other parts same. And ... now it`s asking for permission for gmail. Switch back to 127.0.0.1 - stops asking . Here is 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

So what i am missing? Why it doesnt work for 127.0.0.1 if i regestered this url in api console. And it was working fine with openid. And was working fine with oauth itself without openid. But now when i try to use oauth over openid it doesn`t ask me for permission to gmail.

I had run the PHP, ASP, DOT NET codes they are running absolutely fine and thus sure that the python app will also run correctly. You must be changing the default app. First run the default app provided by them and try to change. If there default app doesn't work then to can also open a bug report to google.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM