Skip to content

Authentication ​

The Brunago API uses Bearer tokens for authentication. All protected endpoints require a valid token in the Authorization header.

Getting Started ​

Obtain a Token ​

To get a Bearer token, register or login:

Both registration and login endpoints return a token together with the User Object of the account:

json
{
  "data": {
    "token": "3|4UgEk8lXwa1D6rbYO8fqMfKhgnwdRuSqZb4Woz083ad0785f",
    "user": {
      "email": "client@example.com",
      "phone": null,
      "role": "client",
      "firstName": null,
      "lastName": null,
      "billingAddress": null,
      "shippingAddress": null,
      "bankAccount": null,
      "company": null,
      "regions": null,
      "registrationNumber": null,
      "emailVerified": false,
      "newsletterSubscribed": false,
      "testimonyAlerts": null,
      "onboardingStatus": null
    }
  }
}

Use the Token ​

Include the token in the Authorization header for all authenticated requests:

http
GET /api/v1/me HTTP/1.1
Host: api.brunago.sk
Authorization: Bearer 3|4UgEk8lXwa1D6rbYO8fqMfKhgnwdRuSqZb4Woz083ad0785f
Accept: application/json

Example with cURL:

bash
curl --request GET \
  --url https://api.brunago.sk/api/v1/me \
  --header 'Authorization: Bearer 3|4UgEk8lXwa1D6rbYO8fqMfKhgnwdRuSqZb4Woz083ad0785f' \
  --header 'Accept: application/json'

Token Management ​

Token Lifecycle ​

  • Creation: Tokens are created during registration or login
  • Storage: Store tokens securely in your application (e.g., secure storage, HttpOnly cookies)
  • Revocation: Tokens are revoked during logout
  • Expiration: Tokens do not expire automatically. A password change revokes the user's other tokens, a password reset revokes all of them

Logout ​

To revoke a token and end the session:

http
POST /api/v1/auth/logout
Authorization: Bearer {your-token}

See Logout for details.

Error Responses ​

401 Unauthorized ​

When authentication is missing or invalid:

json
{
  "message": "Unauthenticated."
}

Common Causes:

  • Token not included in Authorization header
  • Invalid or malformed token
  • Token has been revoked (logged out)
  • Incorrect header format (must be Bearer {token})

A wrong email/password combination on Login is not a 401 — it is a 422 validation error on the email field, so a 401 always means the token is missing or no longer valid.

403 Forbidden ​

When authenticated but not authorized for the action:

json
{
  "message": "Access denied for authenticated users."
}

Common Causes:

  • Wrong user role (e.g., client trying to access expert-only endpoint)
  • Attempting to access another user's resources
  • Accessing an endpoint while already authenticated (e.g., registration)
  • Email not verified on an endpoint that requires it — creating testimonies, creating and withdrawing offers, checkout, accepting offers, completing, cancelling and downloading testimonies, downloading invoices (Access denied for unverified users.)

In production the message of every 403 is the generic Forbidden — see Error Responses.

Security Best Practices ​

Token Security

  • Never expose tokens in URLs, logs, or client-side code
  • Use HTTPS for all API requests to prevent token interception
  • Store securely in secure storage or HttpOnly cookies
  • Implement timeout on client side for inactive sessions
  • Handle 401 errors by redirecting to login

Role-Based Access ​

The API has two user roles with different capabilities:

Client Role ​

  • Create testimonies
  • View and accept offers
  • Make payments
  • Download completed testimonies and their invoices

Expert Role ​

  • View available testimonies
  • Create offers, list their own and withdraw them
  • Upload completed testimonies
  • Download the testimonies they completed and their invoices
  • Manage professional profile

See User Object for role details.

Common Authentication Patterns ​

Initial Registration ​

javascript
// Register new client
const response = await fetch('/api/v1/auth/register/client', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    email: 'client@example.com',
    password: 'SecurePass123',
    // ...other fields
  })
});

const { data: { token, user } } = await response.json();
// Store token securely (e.g., secure cookie, native secure storage)

Authenticated Request ​

javascript
// Make authenticated request
const token = getStoredToken(); // retrieve from secure storage

const response = await fetch('/api/v1/me', {
  headers: {
    'Authorization': `Bearer ${token}`,
    'Accept': 'application/json'
  }
});

Handle 401 Error ​

javascript
// Automatically redirect to login on 401
fetch('/api/v1/protected-endpoint', {
  headers: { 'Authorization': `Bearer ${token}` }
})
.then(response => {
  if (response.status === 401) {
    // Token invalid - redirect to login
    window.location.href = '/login';
  }
  return response.json();
})