我正在设计一个允许用户进行身份验证(使用令牌)并包含同一域内的重定向的 API。现在,对于返回 303 的端点的未经身份验证的请求,
GET /documents/123 --> 303 redirect to `/documents/abc`
GET /documents/abc --> 200
一切都很顺利。
让我们向Authorization
发送标头的同一端点发出经过身份验证的请求。这使请求成为预检请求,浏览器执行预检OPTIONS
请求,即
OPTIONS /documents/123 --> 204 (everything okay, please proceed)
GET /documents/123 --> 303 redirect to `/documents/abc`
此时,浏览器不会GET
在/documents/abc
XMLHttpRequest cannot load http://localhost:8000/people/username/nschloe.
The request was redirected to 'http://localhost:8000/people/YDHa-B2FhMie',
which is disallowed for cross-origin requests that require preflight.
这种行为符合标准:
7.1.5 带预检的跨域请求
如果响应的 HTTP 状态码不在 2xx 范围内
应用网络错误步骤。
这似乎意味着无法对经过身份验证的资源进行重定向,即使重定向位于同一个域 ( localhost
) 上。
这真的是真的吗?有通用的解决方法吗?