Authentication¶
The Book Corners API uses JWT (JSON Web Tokens) for authentication. Authenticated endpoints require a Bearer token in the Authorization header.
Token lifecycle¶
- Register or Login to receive an access/refresh token pair
- Use the access token for API requests (
Authorization: Bearer <access>) - When the access token expires, use the refresh token to get a new one
- When the refresh token expires, log in again
Endpoints¶
Register¶
POST /api/v1/auth/register
Create a new user account and receive a token pair.
Auth required: No
| Field | Type | Required | Description |
|---|---|---|---|
username |
string | Yes | Unique username (3–150 characters) |
email |
string | Yes | Valid email address |
password |
string | Yes | Password (8–128 characters, validated against Django password policies) |
Success (201 Created):
Errors:
| Status | Message |
|---|---|
400 |
"Username already exists." |
400 |
"Email already exists." |
400 |
"Provide a valid email address." |
400 |
Password policy violation message |
429 |
"Too many registration attempts. Please try again later." |
Login¶
POST /api/v1/auth/login
Authenticate with credentials and receive a token pair.
Auth required: No
| Field | Type | Required | Description |
|---|---|---|---|
username |
string | Yes | Username |
password |
string | Yes | Account password |
Success (200 OK):
Errors:
| Status | Message |
|---|---|
401 |
"Invalid credentials." |
429 |
"Too many login attempts. Please try again later." |
Refresh¶
POST /api/v1/auth/refresh
Exchange a valid refresh token for a new access token.
Auth required: No
| Field | Type | Required | Description |
|---|---|---|---|
refresh |
string | Yes | Refresh token from login or registration |
Success (200 OK):
Errors:
| Status | Message |
|---|---|
401 |
"Invalid or expired refresh token." |
429 |
"Too many refresh attempts. Please try again later." |
Me¶
GET /api/v1/auth/me
Return the profile of the currently authenticated user.
Auth required: Yes (Bearer token)
Success (200 OK):
Errors:
| Status | Message |
|---|---|
401 |
Unauthorized (missing or invalid token) |