我有一个启用 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
由于某种原因,IE 似乎正在维护原始请求方法。我试图通过返回 303 来至少打破我的服务器 (app.com) 上的原始 POST 响应,但这也没有解决问题。这是出乎意料的,因为 RFC 2068 指出对于
303 - See Other
回应,以下应予尊重The response to the request can be found under a different URI and SHOULD be retrieved using a GET method on that resource. This method exists primarily to allow the output of a POST-activated script to redirect the user agent to a selected resource.
我什至尝试了 307 响应,但没有成功。有没有人对这里发生的事情有任何想法?
最佳答案
在 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);
}
注意到似乎只有 IE(和旧版本的 IE)才提供这个问题,Chrome、Firefox 和 Safari 似乎都按照规范重定向到 GET。
关于internet-explorer - IE 在 POST -> 重定向 -> GET 场景中忽略 303 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28513449/