Basic Authentication
This document describes the detailed usage of a specific policy. If you are using Apinizer policy structure for the first time or want to learn the general working principles of policies, we recommend that you first read the What is Policy? page.
Overview
Authenticate API requests securely using HTTP Basic Authentication standard. Perform identity verification by decoding username and password information sent in requests with base64.
What is its Purpose?
- Authenticate API requests securely using HTTP Basic Authentication standard. Perform identity verification by decoding username and password information sent in requests with base64.
- Connect to centralized authentication infrastructure with Secret Manager, LDAP, database, or external API integrations. Verify user information securely through Identity/Role Group services.
- Provide access control at endpoint or method level by checking user's roles and permissions. Guarantee that only authorized users can access specific APIs with Authorization configuration.
- Transmit authenticated user information (username, user ID, etc.) to backend services with special header. Enable backend to perform operations in user context.
- Provide multi-layered security by adding advanced security layers such as IP address control, clear auth, and error message customization.
Working Principle
- Request Arrival: For each HTTP/HTTPS request arriving at API Gateway, the request's
Authorizationheader is checked and base64 encoded credentials (username:password) withBasicprefix are searched. - Policy Check: If Base64 Authentication policy is active, the system checks in the following order:
- Is a condition defined? If so, is the condition met?
- Is the policy active (active=true)?
- Is a variable used or is Apinizer default used?
- Authentication Check: Authorization header is decoded and username/password are extracted. Credentials are verified with Identity Role Group service (Secret Manager, LDAP, Database, or API). If
checkClientIpAddressis active, client IP address is also checked. - Decision Making:
- Authentication Successful: If user is verified, authorization (role check) is optionally performed. If
addUserToHeaderis active, user information is transmitted to backend with special header. IfclearAuthis active, Authorization header is not sent to backend. - Authentication Failed: If user credentials are invalid or user has no permission, HTTP 401/403 error is returned.
- Authentication Successful: If user is verified, authorization (role check) is optionally performed. If
- Error Handling: Customizable HTTP status code and error message are returned for requests that do not comply with policy rules.
: characterAfter the base64 decode, only the first : separates the username from the password; every character after it is part of the password (RFC 7617). For example user:12:34 is resolved as the username user and the password 12:34.
Requests from users whose password contained a : were previously rejected with a "missing credentials" error. A : cannot be used in the username — that is what the standard requires.
Features and Capabilities
Basic Features
- HTTP Basic Authentication Support: Authentication in base64 encoded username:password format compliant with RFC 7617 standard. Automatic decode and credential extraction from Authorization header.
- Identity/Role Group Integration: Centralized identity management with Secret Manager, LDAP, Database, or external API services. Secure verification of user information and retrieval of role information.
- Username Variable Support: Writing authenticated username to Apinizer variables. Access to user information throughout policy chain and ability to transfer to backend.
- Active/Passive Status Control: Easily change policy's active or passive status (active/passive toggle). Policy is not applied in passive state but its configuration is preserved.
- Condition-Based Application: Determine when the policy will be applied by creating complex conditions with Query Builder (e.g., only for specific endpoints or header values).