cdbattags / lua-resty-jwt

JWT For The Great Openresty
Apache License 2.0
146 stars 46 forks source link

unable to found cjson & resty.jwt #42

Open saurabhmehta86 opened 4 years ago

saurabhmehta86 commented 4 years ago

Working with nginx r21.

I need to decode jwt token and extract the value of a key out of it. I have downloaded the following libs

  1. https://github.com/cdbattags/lua-resty-jwt#verify
  2. https://github.com/openresty/lua-resty-string
  3. https://github.com/jkeys089/lua-resty-hmac
  4. https://github.com/openresty/lua-cjson

All above mentioned libs are present in /etc/nginx/saurabh/

Nginx.conf

load_module /etc/nginx/ndk_http_module.so; load_module /etc/nginx/ngx_http_lua_module.so; .... http { lua_package_path "/etc/nginx/saurabh/*/lib/?.lua;;"; .... server{ .... rewrite_by_lua_file test.lua; .... } }

test.lua

function validate()
print("<-----Starting validate Client IP----->"); print("<-----r.uri-------------------------->", ngx.var.uri);

if (string.find(ngx.var.uri, '/user/logout'))  then
    print("validate--> Returning Success.");
    return 1;
end

if (ngx.var.uri == '/sso/loggedout') then 
    print("validate-->/sso/loggedout. Returning Success.");
    return 1;
end

local authn_token = ngx.var.cookie_AUTHN_TOKEN;
if (authn_token == undefined)  then
    print("validate-->authn_token cookie is found undefined. Returning Success.");
    return 1;
end

local cjson = require "cjson";
local jwt = require "resty.jwt";
local jwt_obj = jwt:verify("lua-resty-jwt", authn_token);
print("Decoded token is------------------------------>", cjson.encode(jwt_obj));
ngx.say(cjson.encode(jwt_obj));

end

validate()

Error Message

2020/10/31 17:31:28 [error] 12#12: *17 lua entry thread aborted: runtime error: /etc/nginx/test.lua:21: module 'cjson' not found: no field package.preload['cjson'] no file '/etc/nginx/saurabh/lua-resty-jwt/lib/cjson.lua' no file './cjson.lua' no file '/usr/share/nginx-luajit-2.1/cjson.lua' no file '/usr/local/share/lua/5.1/cjson.lua' no file '/usr/local/share/lua/5.1/cjson/init.lua' no file '/usr/share/lua/5.1/cjson.lua' no file '/usr/share/lua/5.1/cjson/init.lua' no file './cjson.so' no file '/usr/local/lib/lua/5.1/cjson.so' no file '/usr/lib/lua/5.1/cjson.so' no file '/usr/local/lib/lua/5.1/loadall.so' stack traceback: coroutine 0: [C]: in function 'require' /etc/nginx/test.lua:21: in function 'validate' /etc/nginx/test.lua:29: in main chunk,

alexzamfir08 commented 3 years ago

i have the same issue

    [C]: in function 'require'
    /usr/local/openresty/nginx/base-validation.lua:2: in main chunk, client: 10.40.18.231, server: fsmcez.adrem.ro, request: "POST /be-mdm/api/KioskMode/GroupCount HTTP/1.1", host: "fsmcez.adrem.ro", referrer: "https://fsmcez.adrem.ro/mdm/app/browser/kioskMode"

2021/08/13 13:19:30 [error] 11819#11819: *89 lua entry thread aborted: runtime error: /usr/local/openresty/nginx/base-validation.lua:2: module 'resty.jwt' not found: no field package.preload['resty.jwt'] no file '/usr/local/openresty/site/lualib/resty/jwt.ljbc' no file '/usr/local/openresty/site/lualib/resty/jwt/init.ljbc' no file '/usr/local/openresty/lualib/resty/jwt.ljbc' no file '/usr/local/openresty/lualib/resty/jwt/init.ljbc' no file '/usr/local/openresty/site/lualib/resty/jwt.lua' no file '/usr/local/openresty/site/lualib/resty/jwt/init.lua' no file '/usr/local/openresty/lualib/resty/jwt.lua' no file '/usr/local/openresty/lualib/resty/jwt/init.lua' no file './resty/jwt.lua' no file '/usr/local/openresty/luajit/share/luajit-2.1.0-beta3/resty/jwt.lua' no file '/usr/local/share/lua/5.1/resty/jwt.lua' no file '/usr/local/share/lua/5.1/resty/jwt/init.lua' no file '/usr/local/openresty/luajit/share/lua/5.1/resty/jwt.lua' no file '/usr/local/openresty/luajit/share/lua/5.1/resty/jwt/init.lua' no file '/usr/local/openresty/site/lualib/resty/jwt.so' no file '/usr/local/openresty/lualib/resty/jwt.so' no file './resty/jwt.so' no file '/usr/local/lib/lua/5.1/resty/jwt.so' no file '/usr/local/openresty/luajit/lib/lua/5.1/resty/jwt.so' no file '/usr/local/lib/lua/5.1/loadall.so' no file '/usr/local/openresty/site/lualib/resty.so' no file '/usr/local/openresty/lualib/resty.so' no file './resty.so' no file '/usr/local/lib/lua/5.1/resty.so' no file '/usr/local/openresty/luajit/lib/lua/5.1/resty.so' no file '/usr/local/lib/lua/5.1/loadall.so' stack traceback: coroutine 0: [C]: in function 'require' /usr/local/openresty/nginx/base-validation.lua:2: in main chunk, client: 10.40.18.231, server: fsmcez.adrem.ro, request: "POST /be-mdm/api/KioskMode/GetRequests HTTP/1.1", host: "fsmcez.adrem.ro", referrer: "https://fsmcez.adrem.ro/mdm/app/browser/kioskMode"

alexzamfir08 commented 3 years ago

did you fixed?

cdbattags commented 3 years ago

I don't believe I was able to recreate when this was originally posted. Let me test this weekend and will respond with my findings.