我对超级堆栈身份验证的理解是,它依靠会话保留用户的ID,该ID用于获取acting_user
。
如果我想与Rails会话脱钩,并使用基于令牌的身份验证,如何设置Hyperstack传输以在每个请求中都包含一个令牌?
基本上,我要问的是如何发送令牌,以使其在acting_user
调用中可用。
class ApplicationController < ActionController::Base
def acting_user
claim = JsonWebToken.verify(params[:token], key: some_key)
@current_user ||= claim[:ok] && User.find(claim[:ok][:user_id])
end
end
其中params[:token]
是根据请求从客户端传递的。
答案 0 :(得分:0)
我不能百分百确定从未使用过令牌授权,但是看这篇好文章,我相信它应该“正常工作”,除非您将授权放到标题中。您将在ApplicationController中实现所需的任何内容,并且可以在登录ControllerOp
中对其进行访问。只要确保您设置了acting_user
https://www.pluralsight.com/guides/token-based-authentication-with-ruby-on-rails-5-api
从客户端到服务器的所有通信都通过ServerOp类,因此您必须修补该类以添加授权。
仅供参考,存在github问题,需要添加一个钩子来简化此操作: