Skip to content

Custom NGINX module to decode the basic authentication header

Notifications You must be signed in to change notification settings

rinconjc/ngx-basic-auth-decode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nginx Basic Authentication Decode Module

Introduction

The ngx-basic-auth-decode module for Nginx is designed to enhance the server's capabilities by extracting the username and password from the request Authorization header and exposing them as variables for use in the Nginx configuration. This module simplifies the retrieval of basic authentication credentials, allowing for more flexible and dynamic configurations.

Installation

  1. You can download the module binaries from the release page, or build it from the source code.

  2. The easiest way to build from sources is to build using the provided Dockerfile.

docker buildx build --build-arg NGX_VERSION=1.23.3 -t ngx-basic-auth-decode . && \
docker_id=$(docker create --rm ngx-basic-auth-decode) && \
docker cp $docker_id:/etc/nginx/modules/libngx_basic_auth_decode.so ./
docker stop $docker_id
  1. Copy the module libngx_basic_auth_decode.so to the nginx modules directory: /etc/nginx/modules/

Usage

Once the ngx-basic-auth-decode module is installed and configured, you can use the variables $basic_auth_user and $basic_auth_pass in your Nginx configuration. These variables will contain the extracted username and password from the Authorization header, respectively.

For example:

# Load the ngx-basic-auth-decode module
load_module modules/libngx-basic-auth-decode_module.so;

location / {
    # ...

    # Pass credentials to a backend application
    proxy_pass http://backend/something

    # Use credentials in a conditional statement
    if ($basic_auth_user = "admin") {
        # Do something for admin users
    }

    # ...
}

License

This module is released under the MIT License. Feel free to use, modify, and distribute it according to your needs.

About

Custom NGINX module to decode the basic authentication header

Resources

Stars

Watchers

Forks

Packages

No packages published