Junior — Middle
Explain the principle of basic authorization and its main features.
sobes.tech AI
Answer from AI
Basic Authentication (Basic Auth) is a simple way to authenticate a user in the HTTP protocol. The client sends the server an Authorization header with the Basic type and a Base64-encoded string containing the username and password in the format username:password.
Example header:
Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
Main features:
- Very simple mechanism, requires no complex setup.
- Password is transmitted as Base64, which is not encryption but encoding — so it is important to use HTTPS to protect data.
- Usually used for simple APIs or internal services.
- Does not support session management; each request must contain authorization data.
Example in Python using the requests library:
import requests
response = requests.get('https://example.com/api/data', auth=('user', 'pass'))
print(response.status_code)