Ruby on rails 我是否必须在我的学生表中添加password_digest列才能运行student.authenticate(password)?即使我在使用Desive?
我正在代码中实现基于令牌的身份验证API,遵循以下链接的步骤: 身份验证_controller.rb是:Ruby on rails 我是否必须在我的学生表中添加password_digest列才能运行student.authenticate(password)?即使我在使用Desive?,ruby-on-rails,api,jwt,token,Ruby On Rails,Api,Jwt,Token,我正在代码中实现基于令牌的身份验证API,遵循以下链接的步骤: 身份验证_controller.rb是: class AuthenticationController < ApplicationController skip_before_action :authenticate_request skip_before_action :verify_authenticity_token def authenticate binding.pry command = Aut
class AuthenticationController < ApplicationController
skip_before_action :authenticate_request
skip_before_action :verify_authenticity_token
def authenticate
binding.pry
command = AuthenticateStudent.call(params[:corporative_email], params[:password])
if command.success?
render json: { auth_token: command.result }
else
render json: { error: command.errors }, status: :unauthorized
end
end
end
一切正常,直到最后一次窥探时代码在student.authenticate(password)
处中断,服务器返回“ArgumentError(参数数量错误(给定0,预期为1)):
。在控制台上,“password”按预期返回“123456”,这对我来说意味着给定的参数编号1不应为零
有人知道这里发生了什么吗?我找到了答案。如果您正在使用Desive并希望遵循下面的教程,请忘记“gem'bcrypt'”部分以及与之相关的所有内容(包括has_secure_password方法) 最后,在commands/authenticate_student.rb处(在我的例子中,我已逐个学生更改了用户)替换以下行:
return student if student && student.authenticate(password)
作者:
有效的密码?是一种设计方法,将执行与身份验证相同的工作
就是这样 我在学生模型中添加了密码摘要栏,错误响应是相同的。在Desive中,数据库可验证栏称为
encrypted\u password
。如果你打算使用Desive,这不是一个很好的指南。由于Deviate建立在Warden的基础上,因此您希望为基于令牌的身份验证创建一个Warden身份验证策略,而不是重新发明轮子并创建无法集成的东西。如果您只是创建一个只使用API的应用程序,我会质疑您是否真的想使用Desive。它为经典的web应用程序提供了大量的功能。我会选择Knock,这是一个更轻的JWT令牌身份验证解决方案。选择一个,使用ActiveModel::HassecurAppassword(即具有安全密码
密码摘要
以及身份验证(密码)
方法来源)或使用Desive身份验证。如果我要使用Desive,那么我会寻找一个实际使用Desive进行身份验证的教程。事实上,我的最终目标是开发一个基于令牌的身份验证API,允许我的webapp请求的验证/注册用户/将内容从webapp下载到将要开发的移动应用程序。目前,我的webapp使用Desive对用户访问进行身份验证。
return student if student && student.authenticate(password)
return student if student && student.valid_password?(password)