OpenID 连接/节点/反应

OpenID Connect /Node /React

有很多关于如何实现 OpenID Connect 身份验证的示例。在 Node 中 - 代码授予(+ 客户端密码)。 有很多示例如何在 React (SPA) 中实现 OpenID - PKCE

的代码授权

我什至知道 PKCE 相当安全,但是我觉得只在客户端进行身份验证是很糟糕的。 每个 React SPA 都有后端(至少应该托管在某个地方)。

我希望在 Node (Express) 中有服务器端来安全地保存客户端密码,并使用 Identity Server 和 React 前端。

正如我已经说过的,有很多“带有模板引擎的节点(Express)”用于身份验证的示例。 但我想使用 React 作为“模板引擎”。

所以,我正在寻找它的完整和正确的实现。同时我找不到它。 谁能帮我找个例子?

不过,您需要在 SPA / 浏览器中进行一些实际保护,2 个常见选项是:

  • 插入 OIDC Client Library 来完成繁重的工作,这样您就不必自己编写太多的安全代码。这个库在接受令牌之前运行了一些严格的安全检查。

  • 使用代理解决方案,使您的 SPA 获得 cookie。 对于 SPA,这更像是一种本土解决方案,而不是基于标准的解决方案

选项 1 的我的资源

选项 2

我在 Internet 上找到了 2 个解决方案。

第一个: Implement social authentication with React + RESTful API

  1. On the frontend, get the 3rd party app’s login popup to appear.
  2. (Still on the frontend) Grab the authentication token the 3rd party app returns after >agreeing to login.
  3. (Yep, still frontend) Send that token to the backend as part of the body of your >request. (I like to use Blobs, but that’s just me.)
  4. On the backend, verify the token.
  5. If the token is authentic, you will receive the user as part of the verification >response (at least that’s the case with Passport.js, which we’ll be using).
  6. Save the user’s data to your database.
  7. Return a JWT token to the frontend. What you do with that token is out of scope for >this tutorial, but it should probably be used to authenticate each of the logged in >user’s actions.

解释得很好,有 github 工作示例 social-auth-example 它仅用于社交身份验证,但我认为制作更通用的东西或至少添加我的 OpenID Connect Auth 没有问题。提供商。

第二个例子: React Authentication with Twitter, Google, Facebook and Github

此方法使用 socket.io。很有意思。

P.S. 因此,我需要弄清楚哪种解决方案更安全,以及是否存在任何安全漏洞。 不是一件容易的事。很遗憾,我的问题没有标准流程。我可以找到 1000 个理由为什么最好在后端完成所有繁重的工作而不是依赖 OIDC 客户端库。第一个原因是我老板:)