User Authentication API Reference

User Authentication API

This section details the API endpoints for managing user authentication and authorization within the SQL database system.

Endpoints

POST /api/v1/auth/login

Authenticate a user and obtain an access token.

Request Body
{
  "username": "string",
  "password": "string"
}
Parameters
  • username (string, required): The username for authentication.
  • password (string, required): The password for authentication.
Responses
Status Code Description Response Body
200 OK Authentication successful.

Example Response (200 OK)

{
  "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "token_type": "Bearer",
  "expires_in": 3600
}
401 Unauthorized Invalid credentials.

Example Response (401 Unauthorized)

{
  "error": "Invalid username or password."
}
500 Internal Server Error An unexpected error occurred.

Example Response (500 Internal Server Error)

{
  "error": "An internal server error occurred."
}

POST /api/v1/auth/register

Register a new user account.

Request Body
{
  "username": "string",
  "password": "string",
  "email": "string"
}
Parameters
  • username (string, required): The desired username. Must be unique.
  • password (string, required): The user's password.
  • email (string, required): The user's email address.
Responses
Status Code Description Response Body
201 Created User registered successfully.

Example Response (201 Created)

{
  "message": "User registered successfully.",
  "user_id": "uuid-1234-abcd"
}
400 Bad Request Invalid input data or missing required fields.

Example Response (400 Bad Request)

{
  "error": "Username or email already exists."
}
500 Internal Server Error An unexpected error occurred.

Example Response (500 Internal Server Error)

{
  "error": "An internal server error occurred."
}

POST /api/v1/auth/logout

Log out the current user and invalidate their token.

Headers
Authorization: Bearer <your_access_token>
Responses
Status Code Description Response Body
200 OK Logout successful.

Example Response (200 OK)

{
  "message": "Successfully logged out."
}
401 Unauthorized No valid authentication token provided.

Example Response (401 Unauthorized)

{
  "error": "Authentication token is missing or invalid."
}
500 Internal Server Error An unexpected error occurred.

Example Response (500 Internal Server Error)

{
  "error": "An internal server error occurred."
}