Erlang 和外部身份验证
一个简单的场景。用户通过一些高级框架(比如说rails)烘焙的表单登录并开始聊天。聊天是用 erlang 编写的,只有经过身份验证的用户才能参与。这意味着,来自客户端的每个请求(包含一些会话 id)都需要在 erlang 代码内以某种方式进行验证(身份验证)。显然 erlang 对登录用户一无所知,需要向框架询问此信息。
问题是如何设计erlang和框架之间的通信才不会造成额外的瓶颈?
我也在考虑将会话 ID 存储在 erlang 中。但是与同步(当新用户登录时)和会话超时相关的额外工作会导致头痛。
A simple scenario. User logs in through the form baked by some high level framework (rails let's say) and starts chatting. Chat is erlang-written and only authenticated users can participate in. That means, every request (containing some session id) comming from client side needs to be verified (authenticated) inside erlang code somehow. Obviously erlang knows nothing about logged users and needs to ask framework for this information.
The question is how to design the communication between erlang and framework to not cause additional bottlenecks?
I was thinking about storing session ids in erlang as well. but additional effort related with synchronization (when new users log in) and session timeouts causes headache.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在这种情况下,没有什么比免费午餐更好的了。如果您将身份验证权限保留在 erlang 之外,您将不得不处理所有这些令人头疼的问题。您可以在 erlang 内部提供一些缓存来提高速度,但这将成为瓶颈,而且您还必须处理所有缓存一致性问题。恕我直言,最好的解决方案是使 erlang 身份验证权威并为高层框架提供身份验证。
There is nothing like free lunch in this case. If you will keep authentication authority outside erlang you would have to deal with all this headache. You can provide some caching inside erlang to improve speed but it will be bottleneck and also you have to deal with all cache coherency issues. IMHO best solution is make erlang authentication authority and provide authentication for high level framework.
如果我们谈论 Rails,我相信可以从 Erlang 连接到同一数据库并从会话表中检索会话数据(前提是您使用数据库作为会话存储)。您甚至可以通过这种方式将数据传递到 Rails。
If we are talking about Rails, I believe it is possible to connect to the same database from Erlang and retrieve session data from sessions table (provided you are using db as session storage). You can even pass data to Rails this way.