Authentication API¶
All authentication endpoints are under /api/auth/.
Overview¶
Bedrud supports multiple authentication methods:
| Method | Endpoint | Description |
|---|---|---|
| Email/Password | POST /api/auth/login |
Traditional login |
| Registration | POST /api/auth/register |
Create account |
| Guest | POST /api/auth/guest-login |
Temporary access |
| OAuth | GET /api/auth/:provider/login |
Social login |
| Passkeys | POST /api/auth/passkey/* |
FIDO2/WebAuthn |
| Token Refresh | POST /api/auth/refresh |
Renew access token |
Token Format¶
Successful authentication returns a pair of JWT tokens:
- Access Token — Short-lived, used in the
Authorizationheader - Refresh Token — Long-lived, used to obtain new access tokens
Using Tokens¶
Include the access token in all authenticated requests:
Endpoints¶
Register¶
Create a new user account.
Request Body:
Response (200):
{
"accessToken": "eyJ...",
"refreshToken": "eyJ...",
"user": {
"id": "uuid",
"email": "user@example.com",
"name": "John Doe",
"role": "user"
}
}
Login¶
Authenticate with email and password.
Request Body:
Response (200):
{
"accessToken": "eyJ...",
"refreshToken": "eyJ...",
"user": {
"id": "uuid",
"email": "user@example.com",
"name": "John Doe",
"role": "user"
}
}
Guest Login¶
Join as a guest without creating an account. Guests have limited permissions.
Request Body:
Response (200):
{
"accessToken": "eyJ...",
"refreshToken": "eyJ...",
"user": {
"id": "uuid",
"name": "Guest User",
"role": "guest"
}
}
Get Current User¶
Retrieve the authenticated user's profile.
Headers: Authorization: Bearer <accessToken>
Response (200):
{
"id": "uuid",
"email": "user@example.com",
"name": "John Doe",
"avatar": "https://...",
"role": "user",
"provider": "email"
}
Refresh Token¶
Exchange a refresh token for a new access token.
Request Body:
Response (200):
Logout¶
Invalidate the current refresh token.
Headers: Authorization: Bearer <accessToken>
Request Body:
Response (200):
OAuth Login¶
Start an OAuth flow with a social provider.
Supported Providers:
| Provider | Path |
|---|---|
/api/auth/google/login |
|
| GitHub | /api/auth/github/login |
/api/auth/twitter/login |
The server redirects the user to the provider's authorization page. After consent, the provider redirects back to the callback URL, and the server returns JWT tokens.
Error Responses¶
All auth endpoints return errors in this format:
| Status | Meaning |
|---|---|
| 400 | Bad request (missing fields, validation error) |
| 401 | Invalid credentials or expired token |
| 409 | Email already registered |
| 500 | Internal server error |