3

I'm an experienced Ruby (Sinatra, Event Machine, Warden, etc) developer and have decided to teach myself Node.js

I've written enough Node now to feel very comfortable with it, and now I'm feeling a bit more ambitious. I would like to wire a simple Sails.js app and a forum built with NodeBB together such that my users can sign into one and be automatically signed in to the other.

I'd like those users to have role-based authentication for access to various parts of the Sails app and also of the forum, so they'd need to share a common RBAC model.

Is Passport suitable for this? And if so, do you have any links to examples?

4

1 回答 1

3

要跨请求保持会话,Passport依赖于Connect,而后者又依赖于包含连接会话 id 的加密 cookie。要在多个应用程序中使用相同的会话,您需要同步您的Express/ Connectcookie 解析器并同步或共享您的会话和用户模型。您需要使用外部会话存储(如 Redis 或 Mongo),并且可能将您的用户数据库与单个应用程序数据库分开。此外,您需要将 cookie 解析器密码复制并粘贴到每个应用程序中。

不过,这并不是最好的方法。的制造商Passport还发布了一个开源 OAuth2 服务器,您可以使用它(结合Passport的 OAuth 2 身份验证支持)为您想要捆绑在一起的所有应用程序提供身份验证。对于您的问题,这是一个更加健壮和可扩展的解决方案,因为您不必担心同步秘密和共享数据库。此外,它允许您编写任何您想要的应用程序(不一定在节点中)并且仍然实现共享单点登录。

(如果这听起来比它的价值还多,你总是可以只使用外部身份提供者。基于 Google 帐户的 OpenID 无需设置,与 无缝集成Passport,让 Google 完成所有工作。)

于 2014-02-23T14:56:19.627 回答