Skip to content

aliprogrammer69/nginx-jwt-module

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nginx jwt auth module

Build Status Build Status Docker pulls

This is an NGINX module to check for a valid JWT.

Inspired by TeslaGov, ch1bo and tizpuppi, this module intend to be as light as possible and to remain simple.

Build:

This module is built inside a docker container, from the alpine image.

Module:

Example Configuration:

server {
    auth_jwt_key "0123456789abcdef" hex; # Your key as hex string
    auth_jwt     off;

    location /secured-by-cookie/ {
        auth_jwt $cookie_MyCookieName;
    }

    location /secured-by-auth-header/ {
        auth_jwt on;
    }

    location /secured-by-auth-header-too/ {
        auth_jwt_key "another-secret"; # Your key as utf8 string
        auth_jwt on;
    }

    location /not-secure/ {}
}

Directives:

Syntax:	 auth_jwt $variable | on | off;
Default: auth_jwt off;
Context: http, server, location

Enables validation of JWT.


Syntax:	 auth_jwt_key string [encoding];
Default: ——
Context: http, server, location

Specifies the key for validating JWT signature (must be hexadecimal).
The encoding otpion may be hex | utf8 | base64 (default is utf8).


Syntax:	 auth_jwt_key_file filename;
Default: ——
Context: http, server, location

Specifies the key for validating JWT signature by reading it from a file.
As auth_jwt_key also defines the expected key, it cannot be provided in the same scope.


Syntax:	 auth_jwt_alg any | HS256 | HS384 | HS512 | RS256 | RS384 | RS512 | ES256 | ES384 | ES512;
Default: auth_jwt_alg any;
Context: http, server, location

Specifies which algorithm the server expects to receive in the JWT.

Build:

./build # Will create a "jwt-nginx" (Dockerfile)

Test:

Default usage:

./test # Will create a "jwt-nginx-test" image from the "jwt-nginx" one (Dockerfile.test)

Set image name:

./test your-image-to-test

example:

./test jwt-nginx-s4 # tests the development image

Use current container:

./test --current container

example:

# docker run --rm --name ngx-test -p 8000:8000 jwt-nginx-test
./test --current ngx-test

About

NGINX module to check for a valid JWT.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 61.2%
  • Shell 29.6%
  • Dockerfile 5.6%
  • Makefile 3.6%