Basic Authentication
Overview
Kong Authentication secures APIs by validating the identity of clients accessing them.
- Ensures only authorized clients can interact with APIs.
- Supports various authentication methods like API keys, JWT, and OAuth2.
We can enable different methods authentication to ensure that the API is only exposed to intended users.
Lab Environment
This lab tests a Kong API Gateway deployment using a FastAPI endpoint. To simplify, both the containerized Kong API Gateway and the FastAPI endpoint are installed locally on a Windows 10 machine. A Docker Compose file is used to deploy Kong, along with other applications like Prometheus, Zipkin, the ELK Stack, and more.
Make sure that you have installed Docker Desktop.
Simply installing Docker in WSL2 without Docker Desktop may introduce some issue when configuring the communication between the containerized Kong API Gateway and the FastAPI application that is installed on the local host.
Pre-requisites
- Postman
- Setup the Kong API Gateway
- Setup the FastAPI Endpoint
- Kong Manager OSS Access
- Create the Routes and Services
- Create the Consumer
Enable the Basic Auth Plugin
To enable the plugin, go to Kong Manager > Plugins > New Plugin > Select Basic Authentication.
Leave the default settings and click Save. It should appear on the plugin list.
Configure the Basic Auth Credentials
To create a consumer, please see Create the Consumer.
Select the consumer and click Credentials > New Basic Auth Credential. Enter the details below and click Save.
Field | Value |
---|---|
Password | !Qwaszxerdfcv |
Username | johnsmith |
Test Basic Auth
To setup Postman, please see Testing with Postman
Open Postman and create a new request. Rename it to Testing FastAPI via Kong - Basic Auth. Enter the URL below and click Send.
http://localhost:8000/kong/healthy
It will return the unauthorized message.
Click the Authorization tab, click the Auth Type dropdown bar, and select Basic Auth. Enter the username and password. Click Send.