node.js - 创建 OAuth API 时的应用程序 token / secret

标签 node.js facebook-graph-api oauth

背景:我正在使用node.js和express来创建API。我已经以标准消费者/用户 key / secret 方式在我的 API 服务器中实现了 OAuth(与 Twitter、Facebook 等的方式相同)。我希望第三方能够以与这些常见 API 相同的方式连接到我的 API。

通常,客户端会与应用程序 token / secret 连接(例如,您作为 Facebook 开发人员创建 Facebook 应用程序,这些应用程序会提供给您)。然而,有时客户端无法为应用程序提供 secret ,因为代码是以不安全的方式实现的。具体来说,我指的是 Javascript 库。例如,开发人员不想在 Javascript 代码中公开他们的应用程序 secret ,因为它是明文并且可能被恶意用户读取。

我注意到 Facebook 避免了这个问题。开发人员只需向 Javascript 库提供应用程序 token (非 secret )。我不明白如何在不从根本上使我的库不安全的情况下为我的 API 提供类似的选项。也就是说,如果 Javascript 客户端库在没有提供安全良好的 token / secret 的情况下向 API 发出请求,那么 OAuth API 如何对这些请求进行身份验证?

从理智上来说,我能想到的最好的解决方案是通过 HTTPS 连接在 Javascript 客户端库和 API 服务器之间进行某种 token 切换,以便返回一个 secret 供库使用。不过,我不太确定如何确保这种交接以防止欺骗。

最佳答案

在大多数情况下,遵循标准比实现某种自定义方式更好。 OAuth2 指定 4 methods in the latest draft (28)执行授权授予流程。 隐式流程就是您在 Facebook 上看到的流程。

正如标准所说:

When issuing an access token during the implicit grant flow, the authorization server does not authenticate the client. In some cases, the client identity can be verified via the redirection URI used to deliver the access token to the client. The access token may be exposed to the resource owner or other applications with access to the resource owner's user-agent.

Implicit grants improve the responsiveness and efficiency of some clients (such as a client implemented as an in-browser application) since it reduces the number of round trips required to obtain an access token. However, this convenience should be weighed against the security implications of using implicit grants, especially when the authorization code grant type is available.

它有一些安全缺陷。

但据我所知,其他方法对您不起作用,因为它们向客户端(第三方网站所有者)或资源所有者(用户)公开 secret ,因此您应该继续使用这个。

关于node.js - 创建 OAuth API 时的应用程序 token / secret ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11400435/

相关文章:

node.js - 如何与 Socket.IO 1.x 和 Express 4.x 共享 session ?

php - 解析php数组并根据条件选择项目

ios - FBSDKLog:请求终结点时出错

javascript - AngularJS oauth 端点在 url 中带有哈希(SpotifyAPI)

mysql - Sequelize findOrCreate 在具有附加唯一键的模型上返回 SequelizeUniqueContraintError

javascript - NodeJS 和 HTML5 Websockets 不能一起工作

iphone - 第二个图像将如何查看 tableview 单元格?

oauth - 为什么不鼓励前端的 OAuth key ?

mysql - 数据库架构允许同一帐户有多个登录机会(Facebook-Connect、Oauth、OpenID 等)

java - 在 java 中加密,在 node.js 中解密