2011-05-09 102 views
0

我在Google App Engine开发中遇到了一个奇怪的问题,每次都在我的post请求中携带正文内容,app引擎无法验证我的帐户,但获取请求的作品。 任何人都可以帮助我吗?我在Chrome扩展开发中使用oauth库ChromeExOAuth。Google AppEngine开发中的OAuth问题

oauth.authorize(function(){ 
     var request = { 
      'method': 'POST', 
      'headers': { 
       "Content-Type" : "application/x-www-form-urlencoded" 
      }, 
      'parameters': { 
      }, 
      'body': "a=b" 
     }; 
     oauth.sendSignedRequest("http://mytabshub.appspot.com/tabshub", function(resp, xhr){ 
      console.log("responding from test server", xhr.responseText); 
     }, request); 
    }); 
+0

“get Request works”意思是你能够将request_token交换为access_token吗? – Jeyara 2011-05-09 23:47:38

+0

是啊!它交换了。该库在查询字符串中携带访问令牌。但我猜应用引擎不会在发送请求时从查询字符串验证帐户。所以验证过程失败。这太奇怪了! – itemon 2011-05-10 00:22:08

+0

我还没有开发Google应用引擎的应用。但我在整合digg和我自己的oauth.net库时遇到同样的问题。然后我用twitter进行测试,它工作正常。但是,我没有把这些文档整理出来。你有没有与像twitter这样的其他服务进行检查?这有助于隔离问题。 – Jeyara 2011-05-10 02:22:32

回答

0

对于POST请求,您必须在请求正文中传递URL编码的oauth参数。在SDK中的初步认识的代码是这样(dev_appserver_oauth.py):

def _Parse(self, request, base_env_dict): 
    """Parses a request into convenient pieces. 

    Args: 
    request: AppServerRequest. 
    base_env_dict: Dictionary of CGI environment parameters. 

    Returns: 
    A tuple (method, path, headers, parameters) of the HTTP method, the 
    path (minus query string), an instance of mimetools.Message with 
    headers from the request, and a dictionary of parameter lists from the 
    body or query string (in the form of {key :[value1, value2]}). 
    """ 
    method = base_env_dict['REQUEST_METHOD'] 
    path, query = dev_appserver.SplitURL(request.relative_url) 
    parameters = {} 
    if method == 'POST': 
    form = cgi.FieldStorage(fp=request.infile, 
          headers=request.headers, 
          environ=base_env_dict) 
    for key in form: 
     if key not in parameters: 
     parameters[key] = [] 
     for value in form.getlist(key): 
     parameters[key].append(value) 
    elif method == 'GET': 
    parameters = cgi.parse_qs(query) 
    return method, path, request.headers, parameters 

见该查询在GET只请求解析。对于POST,它必须在体内。

+0

可能是我发现了一些线索,每次我发送一个应用程序/ x-www-form-urlencoded内容类型,应用引擎拒绝我和抱怨认证失败的发布请求。 ... – itemon 2011-05-11 02:10:15

+0

“你必须通过请求体中的oauth参数url-encoded”吗? RFC似乎只是对顺序和偏好设置了一点。 – Rene 2011-12-18 17:03:25