You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/01/06 14:54:24 UTC

[GitHub] [incubator-apisix] membphis commented on a change in pull request #1027: Jwt authentication plugin compatible with Bearer prefix

membphis commented on a change in pull request #1027: Jwt authentication plugin compatible with Bearer prefix
URL: https://github.com/apache/incubator-apisix/pull/1027#discussion_r363326515
 
 

 ##########
 File path: lua/apisix/plugins/jwt-auth.lua
 ##########
 @@ -89,15 +90,19 @@ function _M.check_schema(conf)
 end
 
 
-local function fetch_jwt_token()
-    local args = ngx.req.get_uri_args()
-    if args and args.jwt then
-        return args.jwt
+local function fetch_jwt_token(ctx)
+    local token = core.request.header(ctx, "authorization")
+    if token then
+        local prefix = sub_str(token, 1, 7)
+        if prefix == 'Bearer ' or prefix == 'bearer ' then
+            return sub_str(token, 8)
+        end
+        return token
     end
 
-    local headers = ngx.req.get_headers()
-    if headers.Authorization then
-        return headers.Authorization
+    token = ngx.ctx.api_ctx.var.arg_jwt
 
 Review comment:
   `ngx.ctx. api_ctx` equals to `ctx`. 
   
   So this line should be `token = ctx.var.arg_jwt` which is simpler.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services