2012-05-02 1 views
2

Google 하이브리드 프로토콜 (oauth over openid)을 구현하려고하는 중입니다. 그리고 Google은 oauth 권한 (gmail 사용)을 요청하지 않으며 openid 만 문제가됩니다.Google 하이브리드 (openid + oauth) 프로토콜이 127.0.0.1에서 작동하지 않습니다.

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 생성 : 여기

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 

가 오픈 ID URL을 생성하는 내 파이썬 코드 : 나는 구글 API를 콘솔에 등록

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에 대한 승인을 요청하지 않습니다. 또한 sanebox.com에서 비슷한 URL을 비교했다. 그리고 예상대로 작동하여 Gmail에 대한 승인을 요청합니다. 그러나 나는 그들의 URL이 작동하고 광산이 아닌 이유에 대한 본질적인 차이를 보지 못했습니다. 더구나, 나는 sanebox URL에 내 URL에 127.0.0.1을 바꿨고, 다른 부분도 동일하게 남겼습니다. 그리고 ... 이제는 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에 대한 승인을 요청하지 않습니다.

답변

0

필자는 PHP, ASP, DOT NET 코드를 실행 했으므로 Python 앱도 올바르게 실행될 것입니다. 기본 앱을 변경해야합니다. 먼저 제공된 기본 앱을 실행하고 변경하십시오. 기본 앱이 작동하지 않으면 Google에 버그 보고서를 열 수 있습니다.

+0

문제는 127.0.0.1로만 실행하는 것입니다. 나는 호스트 파일에 필요한 도메인을 추가하는 것으로 끝났다. 그리고 기본 응용 프로그램은 파이썬의 하이브리드 프로토콜에 존재하지 않습니다. 이미 사용하고있는 openid 용 lib 만 – Aldarund

+0

@Aldarund IT가 로컬 호스트에서도 작동했습니다. 즉, 127.0.0.1입니다. – Vineet1982

+0

두 개의 링크를 게시 했으므로 둘 다 열어 볼 수 있습니다. localhost와의 링크는 Gmail 액세스를 요청하지 않으며 일반 도메인과의 링크는 그렇게 할 것입니다. 링크 간의 차이점은 도메인뿐입니다. – Aldarund