This is an automated email from the ASF dual-hosted git repository.

spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 7045f97  chore(jwt-auth): get JWT by ctx.var.cookie_jwt instead of 
resty.cookie (#5947)
7045f97 is described below

commit 7045f9715569b19d334cd7b4bc79ba10e9084fae
Author: tzssangglass <[email protected]>
AuthorDate: Thu Dec 30 17:09:13 2021 +0800

    chore(jwt-auth): get JWT by ctx.var.cookie_jwt instead of resty.cookie 
(#5947)
---
 apisix/plugins/jwt-auth.lua | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/apisix/plugins/jwt-auth.lua b/apisix/plugins/jwt-auth.lua
index bf52fa0..86a907e 100644
--- a/apisix/plugins/jwt-auth.lua
+++ b/apisix/plugins/jwt-auth.lua
@@ -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")
@@ -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
 
 
@@ -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
 

Reply via email to