oauth on appengine:访问问题

2024-09-29 20:25:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我在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报告了X-Google-Apps-Metadatadomain=systemical.com。在

我怎么解决这个问题?是不是我在Apps/AppEngine中使用子域有问题??在


领域“services.systemic.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()

Tags: appsselfcomtokenurlbaseresponserequest
1条回答
网友
1楼 · 发布于 2024-09-29 20:25:12

我也有类似的问题。尽管我不能更具体地说(我没有代码),但我可以告诉您,问题可能与请求有关。googleappengine对你的请求非常挑剔。在

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

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

但你应该用一个空的尸体寄来:

^{pr2}$

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

相关问题 更多 >

    热门问题