Using JWT Authentication with OpenResty Lua

Sat, Jul 21, 2018 One-minute read

In this post i’ll show how to authenticate nginx using jwt by OpenResty Lua.

First of all what is openresty?

OpenResty is a web application server which uses nginx as a core. With that you can leverage all nginx modules and using lua modules to gain more feature.

We are using authenticator lua. So we need to get our file by cloning this repository.https://github.com/ubergarm/openresty-nginx-jwt

After that just like basic authentication we need to configre our nginx.conf to add these

env JWT_SECRET; #our secret

    location / {
    access_by_lua_file /bearer.lua;
    proxy_pass       http://127.0.0.1:8080;#our backend port
    proxy_set_header Host                    $host;
    proxy_set_header X-Real-IP               $remote_addr;
    proxy_set_header X-Scheme                $scheme;
    proxy_set_header X-Auth-Request-Redirect $request_uri;
           }

After that we can send our request using Bearer authorization to our server