Junior — Middle
How is the authentication token obtained?
sobes.tech AI
Answer from AI
Authentication tokens are usually obtained through a user login process. The client sends a request with credentials (such as username and password) to the authentication server. If the data is correct, the server returns a token — a unique string that confirms the user has been successfully authenticated.
Protocols like OAuth2 or JWT (JSON Web Token) are often used. An example request to obtain a token via REST API:
POST /auth/login HTTP/1.1
Content-Type: application/json
{
"username": "user",
"password": "pass"
}
The server responds with a token:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6..."
}
This token is then included in the headers of subsequent requests to access protected resources.