devise-jwt: Not returning Authorization header on custom devise signup route
Expected behavior
Return Authorization token after signup
Actual behavior
Don’t return Authorization header on signup response
Steps to Reproduce the Problem
Extends the devise registration controller, RegistrationsController < Devise::RegistrationsController
Edit routes to a new one in devise for
Try to make a registration request, works fine but no token is returned
Debugging information
Provide following information. Please, format pasted output as code. Feel free to remove the secret key value.
- Version of
devise-jwtin use 0.5.8 - Version of
railsin use 5.1.3 - Output of
Devise::JWT.config
{:secret=>"32ca22caddb4d61ccf463cbc90c0cd634e83e251a87913bdd8a6b493bc191b4231145b81a132f5a27b77d18b77c18f2d1a8ede5a3e1c664995653744b61583bf",
:expiration_time=>86400,
:dispatch_requests=>nil,
:revocation_requests=>nil,
:aud_header=>nil,
:request_formats=>{}}>
PS already tried to add dispatch_requests
- Output of
Warden::JWTAuth.config{:secret=>“32ca22caddb4d61ccf463cbc90c0cd634e83e251a87913bdd8a6b493bc191b4231145b81a132f5a27b77d18b77c18f2d1a8ede5a3e1c664995653744b61583bf”, :expiration_time=>86400, :aud_header=>“JWT_AUD”, :mappings=>{:user=>“User”}, :dispatch_requests=>[[“POST”, /^/login$/], [“POST”, /^/signup$/]], :revocation_requests=>[[“DELETE”, /^/logout$/]], :revocation_strategies=>{:user=>“JwtBlacklist”}}> - Output of
Devise.mappings
{:user=>
#<Devise::Mapping:0x00007fae440e7730
@class_name="User",
@controllers={:sessions=>"sessions", :registrations=>"registrations", :passwords=>"devise/passwords"},
@failure_app=Devise::FailureApp,
@format=nil,
@klass=#<Devise::Getter:0x00007fae440e6c90 @name="User">,
@modules=[:database_authenticatable, :recoverable, :registerable, :jwt_authenticatable],
@path="",
@path_names={:registration=>"signup", :new=>"new", :edit=>"edit", :sign_in=>"login", :sign_out=>"logout", :password=>"password", :sign_up=>"sign_up", :cancel=>"cancel"},
@path_prefix=nil,
@router_name=nil,
@routes=[:session, :password, :registration],
@scoped_path="users",
@sign_out_via=:delete,
@singular=:user,
@used_helpers=[:session, :password, :registration],
@used_routes=[:session, :password, :registration]>}
-
If your issue is related with not getting a JWT from the server:
- Involved request path, method and request headers
curl -X POST \
http://127.0.0.1:3000/signup \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/json' \
-H 'Postman-Token: 2a378963-f6a9-ac3b-9982-07036429cc7c' \
-d '{
"user": {
"password":"samplepwd",
"email": "xpto@domain.com.br",
"name": "XPTO"
}
}'
- Response headers for that request
Cache-Control:max-age=0, private, must-revalidate
Content-Type:application/json; charset=utf-8
ETag:W/"de32982ba6c3a71c5e1e3203ce2b720b"
Transfer-Encoding:chunked
Vary:Origin
X-Request-Id:b16e3f38-d02c-4957-b787-7686c519fd06
X-Runtime:346.581951
My cors configuration
Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
# TODO: come back here after and add the final DNSs
origins '*'
resource '*',
headers: :any,
methods: %i[get post put patch delete options head],
expose: %w[Authorization]
end
end
Could you check this?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 17 (7 by maintainers)
I used these (notice the missing ^ and $ versus the one I posted at https://github.com/waiting-for-dev/devise-jwt/issues/113#issuecomment-439152651
No need to open a new issue, I just solved.
I was doing a post request /users.json and not to /users, that’s why the token was not set. IDK why, but thank you anyway!
Hello @waiting-for-dev,
I’m trying to signup and signin a user, I don’t get the token back. What am I missing? Thank you in advance
Rails: 5.2.3 Devise Jwt 0.5.9 Devise 4.6
Registrations_controller
devise.rb
In my json response token is nil, because request.env[‘warden…’] is nil.
What am I missing?
Thank you in advance!
EDIT: everything works perfectly in login with both the response header correctly setup I can’t find the header Authorization: Bearer xxx in signup response, neither in json answer