devise-jwt: Authorization header is not being returned
I’m scratching my head with this one and have seen people have had similar issues. I wondering if these doesn’t work if you have Devise custom controllers. Here is my code (I’ve omitted some details for brevity)
config/initializers/devise.rb
config.jwt do |jwt|
jwt.secret = 'c6977142e3d968eb45a955b89b095f55cc8e2640e159682d6a49bfe3c0c2a937a6f4420a181e962dd0cb64233b93756ad34fd6dc8a311d2045b5c06bcbc828e6'
jwt.request_formats = {
landlord: [:json],
}
jwt.dispatch_requests = [
['POST', %r{^/api/lanlords/sign_in.json$}]
]
end
config/routes.rb
devise_for :landlords, defaults: { format: :json }, :controllers => {:sessions => "landlords/sessions"},
:path => '/api/landlords'
config/application.rb
class Application < Rails::Application
config.middleware.insert_before 0, Rack::Cors do
allow do
origins "localhost:3000", "127.0.0.1:3000", "*"
resource "*",
:headers => :any,
:expose => [
"X-Requested-With",
"Content-Type",
"Authorization",
"Accept",
"Client-Security-Token",
"Accept-Encoding",
"iat",
"exp",
"jti"
],
:methods => [:get, :post, :options, :delete, :put, :head]
end
gemfile
gem 'devise'
gem 'devise-jwt', '~> 0.3.0'
request
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 25 (10 by maintainers)
Commits related to this issue
- Remove trailing / from path [#37] — committed to waiting-for-dev/devise-jwt by waiting-for-dev 7 years ago
@russellvaughan Mine worked after I set
dispatch_requestsandrevocation_requestsinconfig/initializers/devise.rb@farverio I’m afraid covering each individual workflow a user could follow when installing it is impossible. The README tries to follow a complete workflow where, of course, you may have to ignore something (like
jwt_payloadin your case). You have a lot more information about revocation strategies further down the file. Docs are far from stopping setup instructions ingem installline. Of course, as always, PR’s improving anything, also the documentation, are more than welcome.Might not be related with original problem, but when this happened to me I realized I forgot the
sign_inmethod in my custom login action. I got the Authorization header when I added it back in.This also worked for me after 2 days of head bangs
I was running into a similar issue upon user registration. I wasn’t using any custom paths or controllers or anything. The issue ended up being that I wasn’t actually signing the user in after registration since they were
confirmable. Pretty dumb on my part, but addingconfig.allow_unconfirmed_access_for = 1.hourindevise.rbresolved that issue.That may or may not be helpful to anyone else, but figured I’d add where I went wrong.
Haha. Yes definitely restarting (but always worth checking!) I am getting a successful sign in (so 200s with user info in the body)
I’m not too sure where to go with this one!
Does everything look correct in my details? Any other logging I can do?
If you configure
dispatch_requestsregexp to end with.jsonand, at the same time, configurerequest_formatsas:json, it means that the matched URL will be*.json.json. Just removedispatch_requestsconfiguration, as it is automatically configured for a regular sign in, and it should work.