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

unable to found cjson & resty.jwt #42

Open
saurabhmehta86 opened this issue Oct 31, 2020 · 3 comments
Open

unable to found cjson & resty.jwt #42

saurabhmehta86 opened this issue Oct 31, 2020 · 3 comments

Comments

@saurabhmehta86
Copy link

saurabhmehta86 commented Oct 31, 2020

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,

@saurabhmehta86 saurabhmehta86 changed the title unable to found cjosn & resty.jwt unable to found cjson & resty.jwt Oct 31, 2020
@alexzamfir08
Copy link

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
Copy link

did you fixed?

@cdbattags
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants