Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(jwt-auth): get JWT by ctx.var.cookie_jwt instead of resty.cookie #5947

Merged
merged 3 commits into from
Dec 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions apisix/plugins/jwt-auth.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
--
local core = require("apisix.core")
local jwt = require("resty.jwt")
local ck = require("resty.cookie")
local consumer_mod = require("apisix.consumer")
local resty_random = require("resty.random")
local vault = require("apisix.core.vault")
Expand Down Expand Up @@ -188,13 +187,11 @@ local function fetch_jwt_token(ctx)
return token
end

local cookie, err = ck:new()
if not cookie then
return nil, err
local val = ctx.var.cookie_jwt
if not val then
return nil, "JWT not found in cookie"
end

local val, err = cookie:get("jwt")
return val, err
return val
end


Expand Down Expand Up @@ -344,10 +341,7 @@ end
function _M.rewrite(conf, ctx)
local jwt_token, err = fetch_jwt_token(ctx)
if not jwt_token then
if err and err:sub(1, #"no cookie") ~= "no cookie" then
core.log.error("failed to fetch JWT token: ", err)
end

core.log.info("failed to fetch JWT token: ", err)
return 401, {message = "Missing JWT token in request"}
end

Expand Down