Google AppEngine 开发中的 OAuth 问题

发布于 2024-11-05 21:20:58 字数 633 浏览 0 评论 0原文

我在 Google App Engine 开发中遇到了一个奇怪的问题,每次在我的发布请求中携带正文内容时,应用程序引擎无法验证我的帐户,但 get 请求有效。 有人可以帮助我吗?我在 Chrome 扩展开发中使用 oauth 库 ChromeExOAuth。

    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);
    });

i have encountered a weird problem in Google App Engine developing, every time is carry a body content in my post request, app engine failed to auth my account, but get request works.
can anybody help me? i'm using oauth library ChromeExOAuth in chrome extension developing.

    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);
    });

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

百思不得你姐 2024-11-12 21:20:58

对于 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,它必须位于正文中。

For POST requests you must pass the oauth parameter url-encoded in the request body. The relavant code in the SDK is this (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

See that the query is only parsed in GET requests. For POST, it must be in the body.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文