2012-05-02 2 views
2

Я пытаюсь реализовать гибридный протокол Google (oauth over openid). И проблема в том, что google не запрашивает разрешение oauth (пытается с gmail), только openid. Я зарегистрировался на Google API консоли:Протокол Google hybrid (openid + oauth) не работает для 127.0.0.1

Client ID for web applications 
Client ID: 248141267047.apps.googleusercontent.com 
Email address:[email protected] 
Client secret: 
Redirect URIs: http://127.0.0.1:8000/oauth2callback 
JavaScript origins:  http://127.0.0.1:8000 

Вот мой питон код для генерации 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 

Он генерирует следующий 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 

И у него есть все необходимые расширения , Но если я перейду к этому URL-адресу, он не попросит разрешения на gmail. Также я сравнивал с похожим URL-адресом от sanebox.com. И он работает так, как ожидалось, и просит разрешения для gmail. Но я не видел никакой существенной разницы, почему их url работает, а мой нет. Более того, я заменил 127.0.0.1 в моем url на sanebox urls и оставил другие части такими же. И ... теперь он просит разрешения для gmail. Вернитесь к 127.0.0.1 - перестаньте спрашивать. Вот код sanebox:

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 

Итак, что мне не хватает? Почему он не работает для 127.0.0.1, если я зарегистрировал этот URL-адрес в консоли api. И он отлично работал с openid. И отлично работал с oauth самостоятельно без openid. Но теперь, когда я пытаюсь использовать oauth над openid, он не просит разрешения на gmail.

ответ

0

Я запускал коды PHP, ASP, DOT NET, они работают абсолютно нормально и, следовательно, уверены, что приложение python будет работать правильно. Вы должны изменить приложение по умолчанию. Сначала запустите предлагаемое по умолчанию приложение и попробуйте изменить его. Если приложение по умолчанию не работает, оно также может открыть отчет об ошибке для google.

+0

Проблема только в том, что она работает с 127.0.0.1. Я закончил с добавлением необходимого домена в файл hosts. И приложение по умолчанию не существует для гибридного протокола для python. Только lib для openid, что я уже использую – Aldarund

+0

@ Aldarund IT работал для меня даже на localhost i.e 127.0.0.1 для меня – Vineet1982

+0

Я разместил две ссылки, вы можете попробовать их открыть. Ссылка с localhost не будет запрашивать у вас доступ к Gmail, в то время как связь с обычным доменом сделает это. Единственная разница между ссылками - это домен. – Aldarund

Смежные вопросы