I'm doing request specs. We use devise-jwt to do authentication, so I need to put the Authorization
header in every request which needs permission to call.
I read the document of Devise JWT so I know I can use
user = fetch_my_user()
headers = { 'Accept' => 'application/json', 'Content-Type' => 'application/json' }
# This will add a valid token for `user` in the `Authorization` header
auth_headers = Devise::JWT::TestHelpers.auth_headers(headers, user)
get '/my/end_point', headers: auth_headers
However, Devise::JWT::TestHelpers.auth_headers
, seems just merge {"Authorization" => "Bearer JWT-TOKEN"}
into the passed-in headers hash.
Why I cannot have directly the hash {"Authorization" => "Bearer JWT-TOKEN"}
, can I?
Or my real question is why it needs Warden::JWTAuth::HeaderParser.to_headers inside the auth_headers
method? what's that used for?
Warden::JWTAuth::HeaderParser.to_headers(headers, token)