📗
Janus Manual
  • Introduction
  • Installation
    • Docker
  • Quick Start
    • Authenticating
    • Add an endpoint
    • Modify (Update/Delete) an endpoint
    • Add Plugins
    • Authentication
    • Adding your API - File System
  • Clustering/HA
  • Proxy Reference
    • Terminology
    • Overview
    • Routing capabilities
    • Load Balacing
    • Request Host header
      • Using wildcard hostnames
      • The preserve_host property
    • Request URI
      • The strip_path property
      • The append_path property
    • Request HTTP method
    • Routing priorities
    • Conclusion
  • Plugins
    • Basic
    • Organization
    • Body Limit
    • Circuit Breaker
    • Compression
    • CORS
    • OAuth
    • Rate Limit
    • Request Transformer
    • Response Transformer
    • Retry
  • Auth
    • OAuth 2.0
  • Misc
    • Health Checks
    • Monitoring
    • Tracing
  • Known Issues
    • Stale HTTP Keep-Alive
  • Upgrade Notes
    • 2.x to 3.x
    • 3.6.x to 3.7.x
Powered by GitBook
On this page
  • Configuration
  • Usage
  • Create an User
  • Using the Credential

Was this helpful?

  1. Plugins

Basic

PreviousPluginsNextOrganization

Last updated 4 years ago

Was this helpful?

Add Basic Authentication to your APIs, with username and password protection. The plugin will check for valid credentials in the Authorization header.

Configuration

The plain basic auth config:

"basic_auth": {
    "enabled": true
}

Here is a simple definition of the available configurations.

Configuration

Description

name

Name of the plugin to use, in this case: basic_auth

enabled

Is the plugin enabled?

Usage

In order to use the plugin, you first need to create some users first. By enabling this plugins in any endpoint There is a simple API that you can use to create new users.

Create an User

You need to create an user that will be used to authenticate. To create an user you can execute the following request:

http -v POST "Authorization:Bearer yourToken" username=lanister password=pay-your-debt

FORM PARAMETER

Description

username

The username to use in the Basic Authentication

password

The password to use in the Basic Authentication

Using the Credential

The authorization header must be base64 encoded. For example, if the credential uses lanister as the username and pay-your-debt as the password, then the field's value is the base64-encoding of lanister:pay-your-debt, or bGFuaXN0ZXI6cGF5LXlvdXItZGVidA==.

Then the Authorization header must appear as:

Authorization: Basic bGFuaXN0ZXI6cGF5LXlvdXItZGVidA== Simply make a request with the header:

curl -X POST -H 'authorization: Bearer yourToken' -H 'content-type: application/json' -d '{"username": "lanister", "password": "pay-your-debt"}'

http -v "Authorization:Basic bGFuaXN0ZXI6cGF5LXlvdXItZGVidA=="

curl -v -H 'Authorization:Basic bGFuaXN0ZXI6cGF5LXlvdXItZGVidA=='

http://localhost:8081/credentials/basic_auth
http://localhost:8081/credentials/basic_auth
http://localhost:8080/example
http://localhost:8080/example