Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby knock gem integration with devise user model

My goal is to implement knock jwt implementation with existing devise user model. I followed README.md instructions from knock github project:
https://github.com/nsarno/knock

When I send, using curl, jwt authentication request for existing user:

curl -X POST -H "Content-Type: application/json" http://127.0.0.1:3000/knock/auth_token --data ' {"auth": {"email": "[email protected]", "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?

like image 696
Karlo Smid Avatar asked Jan 28 '26 22:01

Karlo Smid


1 Answers

After investigating following link:

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. This mechanism requires you to have a password_digest attribute.

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
like image 155
Karlo Smid Avatar answered Jan 31 '26 11:01

Karlo Smid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!