Closed holdenhinkle closed 3 years ago
I'm not sure why the token isn't being set with #set_jwt_token
, probably the headers written to Rodauth's response object aren't somehow being applied to the overall response. The following worked for me:
after_action :set_jwt_token
private
def set_jwt_token
if rodauth(:user).use_jwt? && rodauth(:user).valid_jwt?
response.headers["Authorization"] = rodauth(:user).session_jwt
end
end
I used #session_jwt
just in case there are any session changes during the request to the main app.
It wasn't trivial for me to come up with this solution, so I'll think about how to simplify it and/or document it.
Hi Janko,
Thanks for looking at this, I appreciate it.
This is smart, which I wasn't doing:
I used
#session_jwt
just in case there are any session changes during the request to the main app.
All the best,
Holden
Hi there,
I have a
:user
configuration withjwt
enabled.When I call
rodauth(:user).set_jwt_token(rodauth(:user).jwt_token)
theAuthentication
header doesn't get set. So instead, I set it manually, like this:response.headers['Authorization'] = rodauth(:user).jwt_token
.I looked up the documentation for this method here - https://rodauth.jeremyevans.net/rdoc/index.html It's exactly what I'm doing manually. Here's the source:
Here's the context that I'm using it in, in
app/controllers/application_controller.rb
:Perhaps I'm doing something wrong. I thought I'd report it in case there's a bug.
Thanks!