繁体   English   中英

Rails Knock jwt配置多个参数来登录实体模型

[英]Rails Knock jwt config more than one param to login on the entity model

在设置了一个简单的认证后,我想向auth_params添加一个额外的参数,

在文档中,配置是通过实体模型

    def self.from_token_request request
    # Returns a valid user, `nil` or raise `Knock.not_found_exception_class_name`
    # e.g.
    #   email = request.params["auth"] && request.params["auth"]["email"]
    #   self.find_by email: email
  end

所以我想是这样

def self.from_token_request(request)
    email = request.params["auth"] && request.params["auth"]["email"]
    confirmation_email = request.params["auth"] && request.params["auth"]["confirmation_email"]
    self.find_by(email: email, confirmation_email: confirmation_email)
  end

并且在配置到的UserTokenController的帖子之后

def auth_params
    params.require(:auth).permit(:email, :password, :confirmation_email)
  end

没有生成令牌,也没有使用:confirmation_email参数并导致404错误!

日志

由UserTokenController#create作为/参数处理:{“ auth” => {“ password” =>“ [FILTERED]”,“ email” =>“ manolo@manolo.com”},“ user_token” => {“ auth” => {“密码” =>“ [已过滤]”,“电子邮件” =>“ manolo@manolo.com”}}}用户负载(2.8毫秒)选择“用户”。*从“用户”中查找“用户”。 “ email” = $ 1 AND“ users”。“ confirmation_email”是NULL LIMIT $ 2 [[“ email”,“ manolo@manolo.com”],[“ LIMIT”,1]]↳app / models / user.rb:51 96ms内完成404找不到(ActiveRecord:15.3ms)

因此,请有人可以阐明如何配置敲门的gem以使用更多电子邮件参数进行登录吗?

我必须通过为连接添加第二个参数来测试代码,它在我这一方面工作得很好,请在此处输入图片描述

def auth_params params.permit auth: [:phone, :pin, :has_access] end

`def self.from_token_request

    phone = request.params[:auth]&& request.params[:auth][:phone]
  has_access= request.params[:auth]&& request.params[:auth][:has_access]
  self.find_by phone: phone, has_access: has_access

结束`

如果您已经提交了要约的报价。 我已收到建议以帮助您

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM