代码之家  ›  专栏  ›  技术社区  ›  jldupont

appengine上的oauth:访问问题

  •  0
  • jldupont  · 技术社区  · 14 年前

    我在AppEngine上无法通过OAuth访问资源。

    我的客户机应用程序(在使用python oauth的Linux上)能够检索有效的“访问令牌”,但是当我试图访问受保护的资源(例如。 user = oauth.get_current_user() ),我得到一个 oauth.OAuthRequestError 引发异常。

    headers: {'Content-Length': '21', 'User-Agent': 'musync,gzip(gfe),gzip(gfe)', 'Host': 'services.systemical.com', 'X-Google-Apps-Metadata': 'domain=systemical.com', 'X-Zoo': 'app-id=services-systemical,domain=systemical.com', 'Content-Type': 'application/json', 'Authorization': 'OAuth oauth_nonce="03259912", oauth_timestamp="1282928181", oauth_consumer_key="services.systemical.com", oauth_signature_method="HMAC-SHA1", oauth_version="1.0", oauth_token="1%2Fo0-tcGTfRzkkm449qVxd_8CfCvMcW_0xwL024nO3HgI", oauth_signature="2ojSK6Ws%2BvDxx3Rdlltf53hlI2w%3D"'}

    我怀疑问题可能与域相关,即我正在使用 services.systemical.com 当我看到AppEngine报告 domain=systemical.com 对于 X-Google-Apps-Metadata .

    我该怎么解决?我如何使用Apps/AppEngine子域有问题吗??


    域“services.systemic.com”指向(DNS CNAME)我的appengine应用程序 services-systemical.appspot.com . 域名 systemical.com 与谷歌应用程序域关联。


    更新: 以下是我正在使用的客户端代码:

    class OauthClient(object):
    
        gREQUEST_TOKEN_URL = 'OAuthGetRequestToken'
        gACCESS_TOKEN_URL =  'OAuthGetAccessToken'
        gAUTHORIZATION_URL = 'OAuthAuthorizeToken'
    
        def __init__(self, server, port, base):
            self.server=server
            self.port=port
            self.base=base
            self.request_token_url=self.base+self.gREQUEST_TOKEN_URL
            self.access_token_url=self.base+self.gACCESS_TOKEN_URL
            self.authorize_token_url=self.base+self.gAUTHORIZATION_URL
            self.connection = httplib.HTTPConnection("%s:%d" % (self.server, self.port))
    
        def fetch_request_token(self, oauth_request):
            self.connection.request(oauth_request.http_method, self.request_token_url, headers=oauth_request.to_header()) 
            response = self.connection.getresponse()
            print response.status, response.reason
            print response.msg
            return oauth.OAuthToken.from_string(response.read())
    
        def fetch_access_token(self, oauth_request):
            self.connection.request(oauth_request.http_method, self.access_token_url, headers=oauth_request.to_header()) 
            response = self.connection.getresponse()
            return oauth.OAuthToken.from_string(response.read())
    
        def authorize_token(self, oauth_request):
            self.connection.request(oauth_request.http_method, oauth_request.to_url()) 
            response = self.connection.getresponse()
            return response.read()
    
    1 回复  |  直到 14 年前
        1
  •  0
  •   pedromcaraujo    14 年前

    我也有类似的问题。虽然我不能说得更具体(我没有带代码),但我可以告诉您,问题可能与请求有关。Google App Engine对你的请求非常挑剔。

    尝试将请求正文发送为空。例如,这是通常的呼叫:

    import httplib
    connection = httplib.HTTPSConnection('server.com')
    connection.request('POST', REQUEST_TOKEN_URL,body = urlencode(body), headers = {'Authorization': header})
    

    但你应该带着一具空尸体来:

    connection.request('POST', REQUEST_TOKEN_URL, headers = {'Authorization': header})
    

    报头包含OAuth所需的所有信息。