OAuth2 : redirect_uri post 领英和脸书

OAuth2 : redirect_uri post LinkedIn & Facebook

我正在执行服务器端 oAuth2 流程。

我注意到 google 为他们的 oAuth2 登录 API 添加了一个很酷的功能 redirect_uri=postmessage 所以我们不会在浏览器上显示真实的 redirect_uri url 栏和 authorization code 将不会包含在重定向中 url。

对于 linkedin,当用户同意与该应用共享他的个人数据时,响应 url 如下所示:

http://dev.localhost.com:8080/auth/linkedin?code=xxxxxxxxxxx&state=yyyyyyyyyyyyy

Google也是一样的,除非我们用postmessage代替真正的redirect_uri

如果 redirect_uri + 响应代码设置在 url 每个恶意脚本都可以从 url 中检索 returned code =] 并执行自己的身份验证。

那么,有什么方法可以隐藏 LinkedIn 和 Facebook 的 return 参数和 redirect_uri 参数吗?

LinkedIn 和 Facebook 不容易受到访问 redirect_uri 的恶意脚本的攻击。

假设您使用推荐的 response_type=code,这两个 API 都要求您从您的服务器发出一个请求,其中包括您的 API 秘密和 code 值,以便获取用户令牌。 LinkedIn 在 Exchange Authorization Code for a Request Token and Facebook describes this in Exchanging code for an access token.

中对此进行了描述

可以启用 Facebook 的额外安全性,要求 every request be signed with your API secret. Additional protection in general can be had by using a strong Content Security Policy 首先帮助防止来自 运行 的恶意脚本。并确保通过 TLS 专门托管您的网站,以防止您自己的 JavaScript 被修改。