Skip to content

Commit 1c34efc

Browse files
committed
Adds the HTTP_AUTHORIZATION header if the token should be revoked, and before the rest of the middleware is called.
Related to #5 Bump version to 0.5.0
1 parent 423d09f commit 1c34efc

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/devise/jwt/cookie/middleware.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,19 @@ def initialize(app)
1212
end
1313

1414
def call(env)
15+
token_should_be_revoked = token_should_be_revoked?(env)
16+
if token_should_be_revoked
17+
# add the Authorization header, devise-jwt needs this to revoke tokens
18+
# we need to make sure this is done before the other middleware is run
19+
request = ActionDispatch::Request.new(env)
20+
env['HTTP_AUTHORIZATION'] = "Bearer #{CookieHelper.new.read_from(request.cookies)}"
21+
end
22+
1523
status, headers, response = app.call(env)
1624
if headers['Authorization'] && env[ENV_KEY]
1725
name, cookie = CookieHelper.new.build(env[ENV_KEY])
1826
Rack::Utils.set_cookie_header!(headers, name, cookie)
19-
elsif token_should_be_revoked?(env)
27+
elsif token_should_be_revoked
2028
name, cookie = CookieHelper.new.build(nil)
2129
Rack::Utils.set_cookie_header!(headers, name, cookie)
2230
end

lib/devise/jwt/cookie/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Devise
22
module JWT
33
module Cookie
4-
VERSION = '0.4.0'
4+
VERSION = '0.5.0'
55
end
66
end
77
end

0 commit comments

Comments
 (0)