根据OAuth2.0 spec ,重定向 URI 不应包含片段标识符。
The redirection endpoint URI MUST be an absolute URI as defined by [RFC3986] Section 4.3. The endpoint URI MAY include an "application/x-www-form-urlencoded" formatted (per Appendix B) query component ([RFC3986] Section 3.4), which MUST be retained when adding additional query parameters. The endpoint URI MUST NOT include a fragment component.
规范做出此类限制是否有任何具体原因?
提前致谢!
最佳答案
URL 片段永远不会离开您的浏览器。它们旨在供前端使用(这意味着如果您将哈希片段放入浏览器中的 URL 并访问它,片段将不会到达服务器端)。
因此,当授权服务器通过用户代理重定向时,片段将仅保留在用户代理上。从 OAuth 的角度来看,这可能会带来不必要的复杂性和安全漏洞。这在Insufficient Redirect URI Validation下进一步突出显示。在最佳实践草案中。
关于oauth-2.0 - 为什么 OAuth2 不允许在重定向 URI 中包含片段标识符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60257717/