I want to create a rails API with the devise gem for authentication. I am using Chrome Postman to check API outputs.
My environments:
What I did:
ran
rails new my_api
cd my_api
added devise gem in Gemfile
bundle install
added
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
to environment/development.rb
rails console
After that I tried to login from postman.
I gave email
and password
into headers of postman.
POST http://localhost:3000/users/sign_in
headers
email abcd@gamilcom
password abcd1234
but it's not authenticating. What do I need to do?
The user enters his details and sends the request to the server. If the information is correct, the server creates a unique HMACSHA256 encoded token, also known as the JSON (JWT) web token. The client maintains JWT and executes all the following requests on the server with the attached token.
You may want to use knock or devise_token_auth in an API context. Be carreful, your email seems to be invalid. I don't know Postman but the POST parameters should live in the body of your HTTP request.
HTTP Basic Auth is turned off by default on Devise. It is simple to enable it and for most API purposes, basic auth is sufficient.
You need to do two things to enable HTTP basic auth:
:database_authenticatable
strategy in your user/account modelconfig.http_authenticatable = true
in the devise initializerSee more here: https://github.com/plataformatec/devise/wiki/How-To:-Use-HTTP-Basic-Authentication
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With