简体   繁体   English

Ruby敲宝石与设计用户模型集成

[英]Ruby knock gem integration with devise user model

My goal is to implement knock jwt implementation with existing devise user model. 我的目标是使用现有的设计用户模型实现knock jwt实现。 I followed README.md instructions from knock github project: 我按照来自knock github项目的README.md指令:
https://github.com/nsarno/knock https://github.com/nsarno/knock

When I send, using curl, jwt authentication request for existing user: 当我使用curl发送现有用户的jwt身份验证请求时:

curl -X POST -H "Content-Type: application/json" http://127.0.0.1:3000/knock/auth_token --data ' {"auth": {"email": "user@example.com", "password": "password"}} ' —verbose

I got following exception: 我有以下异常:

ArgumentError - wrong number of arguments (given 0, expected 1): devise (3.4.1) lib/devise/models/database_authenticatable.rb:147:in password_digest' activemodel (4.2.5.2) lib/active_model/secure_password.rb:103:in authenticate'

What could be the problem here? 这可能是什么问题?

After investigating following link: 调查以下链接后:

http://api.rubyonrails.org/classes/ActiveModel/SecurePassword/ClassMethods.html#method-i-has_secure_password http://api.rubyonrails.org/classes/ActiveModel/SecurePassword/ClassMethods.html#method-i-has_secure_password

this is important piece of information: 这是重要的信息:

Adds methods to set and authenticate against a BCrypt password. 添加用于设置和验证BCrypt密码的方法。 This mechanism requires you to have a password_digest attribute. 此机制要求您具有password_digest属性。

Since devise uses in user model method: 由于设计用于用户模型方法:

encrypted_password

you need in User active model create following method: 您需要在用户活动模型中创建以下方法:

def password_digest
    self.encrypted_password
end

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

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