2010-08-27 43 views
0

我在AppEngine上通过OAuth访问资源时遇到了一些困难。我的客户端应用程序(在Linux上使用python-oauth)能够检索有效的“访问令牌”,但当我尝试访问受保护的资源时(例如user = oauth.get_current_user()),我得到一个oauth.OAuthRequestError异常抛出。appengine上的oauth:访问问题

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为X-Google-Apps-Metadata报告domain=systemical.com

我该如何解决这个问题?使用Apps/AppEngine如何使用子域名是否存在问题?


域 “services.systemical.com” 点(DNS CNAME)我的AppEngine应用程式services-systemical.appspot.com。域名systemical.com与Google Apps域相关联。


更新:这里是我使用的客户端代码:

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() 

回答

0

我也有类似的问题。虽然我不能更具体(我没有与我的代码),我可以告诉你,问题可能与请求有关。 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的所有信息。

+0

我已经更新了这个问题:我正在使用令牌请求的'标题':仍有问题。 – jldupont 2010-09-01 23:02:40