Ruby on rails SecureCompare安全UTIL的授权问题
我想为我现有的应用程序构建API。已生成特殊身份验证令牌并将其添加到我的数据库中。问题是,在比较用户应用程序发送的令牌与数据库中定义的令牌时,我会遇到这样的错误: NameError(未初始化的常量ActiveSupport::SecurityUtils): app/controllers/api/v1/base\u controller.rb:64:in'authenticate\u user!' 渲染 /home/snow/.rvm/gems/ruby-2.0.0-p643/gems/actionpack-4.0.2/lib/action\u dispatch/middleware/templates/rescues//u source.erb (25.4ms) 渲染 /home/snow/.rvm/gems/ruby-2.0.0-p643/gems/actionpack-4.0.2/lib/action\u dispatch/middleware/templates/rescues//u trace.erb (0.8毫秒) 渲染 /home/snow/.rvm/gems/ruby-2.0.0-p643/gems/actionpack-4.0.2/lib/action\u dispatch/middleware/templates/rescues//u request\u and\u response.erb (29.9毫秒) 渲染 /home/snow/.rvm/gems/ruby-2.0.0-p643/gems/actionpack-4.0.2/lib/action\u dispatch/middleware/templates/rescues/diagnostics.erb在rescues/layout中(74.0ms) 或者你可以看到邮递员的回复: 在网上搜索答案,似乎是Rails版本和Ruby on rails SecureCompare安全UTIL的授权问题,ruby-on-rails,api,ruby-on-rails-4,authorization,activesupport,Ruby On Rails,Api,Ruby On Rails 4,Authorization,Activesupport,我想为我现有的应用程序构建API。已生成特殊身份验证令牌并将其添加到我的数据库中。问题是,在比较用户应用程序发送的令牌与数据库中定义的令牌时,我会遇到这样的错误: NameError(未初始化的常量ActiveSupport::SecurityUtils): app/controllers/api/v1/base\u controller.rb:64:in'authenticate\u user!' 渲染 /home/snow/.rvm/gems/ruby-2.0.0-p643/gems/act
secure\u compare
方法不兼容造成的。(我的应用程序是在Rails 4.0.2上构建的,但需要使用Rails 4.2.0。)Rails升级是解决我的问题的唯一解决方案,还是有其他方法可以安全地比较令牌而不使用ActiveSupport::SecurityUtils
身份验证代码如下:
def authenticate_user!
token, options = ActionController::HttpAuthentication::Token.token_and_options(request)
user_phone_number = options.blank?? nil : options[:phone_number]
user = user_phone_number && User.find_by(phone_number: user_phone_number)
if user && ActiveSupport::SecurityUtils.secure_compare(user.authentication_token, token)
@current_user = user
else
return unauthenticated!
end
end
你找到解决办法了吗?你找到解决办法了吗?