IE忽略POST中的303重定向 - >重定向 - > GET场景

Jas*_*ims 6 internet-explorer redirect http-post post-redirect-get

我有一个启用OAuth2的站点,它遇到了与IE如何处理303响应有关的问题.在流程中,发生3次重定向.

### Chrome/Firefox
POST idp.com/login           (res 302 -> idp.com/authenticate)
GET  idp.com/authenticate    (res 302 -> app.com/oauth2/callback)
GET  app.com/oauth2/callback (res 303 -> app.com/home)
GET  app.com/home

### IE
POST idp.com/login           (res 302 -> idp.com/authenticate)
POST idp.com/authenticate    (res 302 -> app.com/oauth2/callback)
POST app.com/oauth2/callback (res 303 -> app.com/home)
POST app.com/home
Run Code Online (Sandbox Code Playgroud)

由于某种原因,IE似乎维护了原始的请求方法.我尝试通过返回303来至少从我的服务器(app.com)上的原始POST响应中断,但这也没有解决问题.这是意料之外的,因为RFC 2068声明对于303 - See Other响应,应遵循以下内容

可以在不同的URI下找到对请求的响应,并且应该使用该资源上的GET方法检索.此方法主要用于允许输出POST激活的脚本以将用户代理重定向到选定的资源.

我甚至尝试了307响应但没有成功.有没有人对这里发生的事情有任何想法?

wom*_*ine 0

在 LinkedIn OAuth 和我的应用程序中遇到类似的问题后,我以一种特别不优雅的方式解决了这个问题。我允许对回调地址使用 POST 方法,然后在 servlet 实现内部将其视为 GET 调用。

    @RequestMapping(value = ApiValues.LINKEDIN_CALLBACK, method = RequestMethod.POST)
public void doPost(HttpServletRequest request, HttpServletResponse response,
        @RequestParam(value = "oauth_token", required = false) String tokenString,
        @RequestParam(value = "oauth_verifier", required = false) String verifierString) throws ServletException, IOException {

    handleCallBack(request, response, tokenString, verifierString);
}


@RequestMapping(value = ApiValues.LINKEDIN_CALLBACK, method = RequestMethod.GET)
public void doGet(HttpServletRequest request, HttpServletResponse response,
        @RequestParam(value = "oauth_token", required = false) String tokenString,
        @RequestParam(value = "oauth_verifier", required = false) String verifierString) throws ServletException, IOException {

    handleCallBack(request, response, tokenString, verifierString);
}
Run Code Online (Sandbox Code Playgroud)

注意到似乎只是 IE(以及旧版本的 IE)提供了这个问题,Chrome、Firefox 和 Safari 似乎都按照规范重定向到 GET。