简体   繁体   English

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

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

after setup a simple auth with knock i'd like to add a extra param to auth_params, 在设置了一个简单的认证后,我想向auth_params添加一个额外的参数,

in the docs the config is via-the-entity-model 在文档中,配置是通过实体模型

    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

So i presumed so 所以我想是这样

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

And after a post to UserTokenController that is config to 并且在配置到的UserTokenController的帖子之后

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

Did not generated the token nor the :confirmation_email params was used and caused 404 error! 没有生成令牌,也没有使用:confirmation_email参数并导致404错误!

the logs 日志

Processing by UserTokenController#create as / Parameters: {"auth"=>{"password"=>"[FILTERED]", "email"=>"manolo@manolo.com"}, "user_token"=>{"auth"=>{"password"=>"[FILTERED]", "email"=>"manolo@manolo.com"}}} User Load (2.8ms) SELECT "users".* FROM "users" WHERE "users"."email" = $1 AND "users"."confirmation_email" IS NULL LIMIT $2 [["email", "manolo@manolo.com"], ["LIMIT", 1]] ↳ app/models/user.rb:51 Completed 404 Not Found in 96ms (ActiveRecord: 15.3ms) 由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)

So, please someone can clarify how to config the knock gem to login with more than email params? 因此,请有人可以阐明如何配置敲门的gem以使用更多电子邮件参数进行登录吗?

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

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

` def self.from_token_request `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

end ` 结束`

If you have submitted the offer on upwork. 如果您已经提交了要约的报价。 I am sent a proposal to help you 我已收到建议以帮助您

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

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