Skip to main content

Authentication

Creating an Account

To create an account, you need to send a POST request to our API with the account details. This will register a new account for your betting business.

curl -X POST "$baseUrl/auth/register/account" \
-H "Content-Type: application/json" \
-d '{
"name": "My Betting Business",
"email": "business@example.com",
"password": "securepassword"
}'

Upon successful creation, the API will respond with the account's details:

{
"message": "Account created successfully"
}

Logging In

To log in to your account, you need to send a POST request to our API with your email and password. This will authenticate your account and return a token.

curl -X POST "$baseUrl/auth/login/account" \
-H "Content-Type: application/json" \
-d '{
"email": "business@example.com",
"password": "securepassword"
}'

Upon successful login, the API will respond with the authentication token:

{
"data": {
"token": "OCFUBbMIX4PGXb4ROw5xKVC8kW8tGSBh"
},
"message": "Logged into account successfully"
}

Logging Out

To log out from your account, you need to send a POST request to our API. This will invalidate your authentication token.

curl -X POST "$baseUrl/auth/logout/account?logout_all=true" \
-H "Authorization: Bearer $token" \
-H "Content-Type: application/json"

Upon successful logout, the API will respond with a confirmation message:

{
"message": "Logged out successfully"
}

Creating API Keys

To create API keys for your account, you need to send a POST request to our API. This will generate a new API key and secret for your account.

curl -X POST "$baseUrl/auth/account/generate-keys" \
-H "Authorization: Bearer $token" \
-H "Content-Type: application/json"

Upon successful generation, the API will respond with the API key and secret:

{
"data": {
"api_key": "api_key_k4rBSsfzj6SyJbsKOT3YXRXsmKRZuYT4",
"api_secret": "api_secret_80d6bx3NNRsqELP6in2eVS56jSGyVNhiUtRMeImnUoJWc8DQYgLnwm1gH45PISQN",
"base64_encoded": "YXBpX2tleV9rNHJCU3Nmemo2U3lKYnNLT1QzWVhSWHNtS1JadVlUNDphcGlfc2VjcmV0XzgwZDZieDNOTlJzcUVMUDZpbjJlVlM1NmpTR3lWTmhpVXRSTWVJbW5Vb0pXYzhEUVlnTG53bTFnSDQ1UElTUU4="
},
"message": "Api keys generated successfully"
}

Verify Account Email

To verify your account email, you need to click on the verification link that was sent to your email address or use the verification token in a GET request to our API.

curl -X GET "$baseUrl/auth/account/verify-email?token=your_verification_token"

Upon successful verification, the API will respond with a confirmation message:

{
"message": "Email verified successfully"
}

Resend Verification Email

If you didn't receive the verification email or the token has expired, you can request a new verification email. You need to be authenticated to use this endpoint.

curl -X POST "$baseUrl/auth/account/resend-verification-email" \
-H "Authorization: Bearer $token" \
-H "Content-Type: application/json"

Upon successful request, the API will respond with a confirmation message:

{
"message": "Verification email sent successfully"
}

Password Reset

Authenticated users can reset their password by providing their current password and a new password. This endpoint requires authentication and validates the current password before allowing the reset.

Requirements

  • User must be authenticated (using either Bearer token or API key)
  • Current password must be provided and correct
  • New password must be at least 8 characters long
  • New password and password confirmation must match

Security Features

  • Current Password Validation: Requires the current password (not a "forgot password" flow)
  • Dual Authentication Support: Works with both Bearer tokens and API keys
# Using Bearer Token
curl -X POST "$baseUrl/auth/account/reset-password" \
-H "Authorization: Bearer $token" \
-H "Content-Type: application/json" \
-d '{
"password": "current_password",
"new_password": "new_password_min_8_chars",
"password_confirmation": "new_password_min_8_chars"
}'

# Using API Key Authentication
curl -X POST "$baseUrl/auth/account/reset-password" \
-u "api_key:api_secret" \
-H "Content-Type: application/json" \
-d '{
"password": "current_password",
"new_password": "new_password_min_8_chars",
"password_confirmation": "new_password_min_8_chars"
}'

Upon successful password reset, the API will respond with a confirmation message:

{
"message": "Password reset successfully"
}

Error Responses

Validation Errors (400 Bad Request):

{
"message": [
"password should not be empty",
"new_password must be longer than or equal to 8 characters",
"password_confirmation should not be empty"
],
"error": "Bad Request",
"statusCode": 400
}

Incorrect Current Password (400 Bad Request):

{
"status": 400,
"error": "Current password is incorrect"
}

Password Mismatch (400 Bad Request):

{
"status": 400,
"error": "New password and confirmation do not match"
}

Unauthorized (401):

{
"message": "Unauthorized",
"statusCode": 401
}

Forgot Password Flow

For users who have forgotten their password, we provide a secure two-step process that uses email-based token verification. This flow is designed for unauthenticated users who cannot access their account.

Password Reset vs Forgot Password

FeaturePassword ResetForgot Password
Authentication Required✅ Required (Bearer token or API key)❌ No authentication needed
Current Password✅ Must provide current password❌ Not required
Email Verification❌ Not required✅ Uses email token
Use CaseAuthenticated users changing passwordUsers who forgot their password
Security LevelHigh (requires current password)High (email token validation)

Complete Flow Overview

The forgot password process consists of two main steps:

  1. Request Password Reset Token - User provides email and receives a reset token
  2. Create New Password - User uses the token to set a new password

Security Features

  • Email Enumeration Protection: Always returns success (doesn't reveal if email exists)
  • Token Expiration: Reset tokens expire after 1 hour
  • Automatic Cleanup: Previous tokens are deleted when new ones are requested
  • Unique Tokens: Each token is a unique 8-character numeric code
  • Email Notifications: Users receive confirmation emails for password changes
  • Account Verification: Automatically verifies email if unverified

Step 1: Request Password Reset Token

The first step allows users to request a password reset token by providing their email address.

curl -X POST "$baseUrl/auth/account/forgot-password" \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com"
}'

Response (Always Success for Security):

{
"message": "If an account with this email exists, a password reset email has been sent"
}

Step 2: Create New Password with Token

After receiving the 8-character token via email, users can set their new password.

curl -X POST "$baseUrl/auth/account/create-password-for-forgot-password" \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"token": "12345678",
"password": "new_secure_password123",
"password_confirmation": "new_secure_password123"
}'

Success Response:

{
"message": "Password created successfully"
}

Error Responses

Step 1 - Request Token Errors:

Invalid Email Format (400 Bad Request):

{
"message": [
"email must be an email",
"email should not be empty"
],
"error": "Bad Request",
"statusCode": 400
}

Step 2 - Create Password Errors:

Validation Errors (400 Bad Request):

{
"message": [
"email should not be empty",
"token should not be empty",
"password must be longer than or equal to 8 characters",
"password_confirmation should not be empty"
],
"error": "Bad Request",
"statusCode": 400
}

Invalid or Expired Token (400 Bad Request):

{
"status": 400,
"error": "Invalid or expired reset token"
}

Password Mismatch (400 Bad Request):

{
"status": 400,
"error": "Password and confirmation do not match"
}

Frontend Integration

For frontend applications, here's a typical integration pattern:

// Complete forgot password flow example
class ForgotPasswordService {
constructor(baseUrl) {
this.baseUrl = baseUrl;
}

// Step 1: Request reset token
async requestReset(email) {
try {
const response = await fetch(`${this.baseUrl}/auth/account/forgot-password`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email })
});

return await response.json();
} catch (error) {
throw new Error('Failed to request password reset');
}
}

// Step 2: Create new password
async createPassword(email, token, password, passwordConfirmation) {
try {
const response = await fetch(`${this.baseUrl}/auth/account/create-password-for-forgot-password`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
email,
token,
password,
password_confirmation: passwordConfirmation
})
});

if (!response.ok) {
const error = await response.json();
throw new Error(error.error || 'Failed to create password');
}

return await response.json();
} catch (error) {
throw error;
}
}
}

// Usage example
const forgotPasswordService = new ForgotPasswordService('https://your-api.com');

// Handle forgot password form submission
async function handleForgotPassword(email) {
try {
await forgotPasswordService.requestReset(email);
// Show success message - always success for security
showMessage('If an account exists, a reset email has been sent');
} catch (error) {
showError('An error occurred. Please try again.');
}
}

// Handle password creation form submission
async function handlePasswordCreation(email, token, password, confirmPassword) {
try {
await forgotPasswordService.createPassword(email, token, password, confirmPassword);
showMessage('Password updated successfully! You can now log in.');
redirectToLogin();
} catch (error) {
showError(error.message);
}
}

Token Management

  • Generation: Unique 8-character numeric tokens (e.g., "12345678")
  • Expiration: 1 hour from generation
  • Cleanup: Previous tokens are automatically deleted when new ones are requested
  • Usage: Single-use tokens that are deleted after successful password creation
  • Security: Tokens cannot be used to authenticate for other endpoints

Account Verification Bonus

When users successfully complete the forgot password flow:

  • If their email was previously unverified, it gets automatically verified
  • The email_verified_at field is set to the current timestamp
  • This provides a seamless experience for users who forgot their password before verifying their email

Authentication Methods

Authentication with Tokens

To demonstrate authentication using tokens, we will use the example of retrieving the authenticated user's details. This involves sending a GET request to our API, which allows you to verify the authentication status and access the user's information.

curl -X GET "$baseUrl/auth/account/me" \
-H "Authorization: Bearer $token" \
-H "Content-Type: application/json"

Upon successful authentication, the API will respond with the user's account details:

{
"data": {
"id": 1,
"name": "First Account",
"email": "first@email.com",
"api_key_generated_at": "2025-03-06T02:04:10.580Z",
"created_at": "2025-03-06T00:44:11.292Z",
"updated_at": "2025-03-06T02:04:10.581Z"
},
"message": "authentication data"
}

Authentication with API Keys

To demonstrate authentication using API keys, you can use the API keys in one of two ways:

  1. Using the base64_encoded value directly:
Authorization: Basic ams4c2E3ZGZnOThzN2RmOThnN3NkZmc4Nzo4c2Q3Zmc4c2Q3Zmc4c2Q3Zjk4Z3M3ZGY5OGc=
  1. Using the api_key as username and api_secret as password for Basic Auth.
# Using base64_encoded value
curl -X GET "$baseUrl/auth/account/me" \
-H "Authorization: Basic ams4c2E3ZGZnOThzN2RmOThnN3NkZmc4Nzo4c2Q3Zmc4c2Q3Zmc4c2Q3Zjk4Z3M3ZGY5OGc=" \
-H "Content-Type: application/json"

# Using api_key and api_secret for Basic Auth
curl -X GET "$baseUrl/auth/account/me" \
-u "jk8sa7dfg98s7df98g7sdfg87:8sd7fg8sd7fg8sd7f98gs7df98g" \
-H "Content-Type: application/json"

Upon successful authentication, the API will respond with the user's account details:

{
"data": {
"id": 1,
"name": "First Account",
"email": "first@email.com",
"api_key_generated_at": "2025-03-06T02:04:10.580Z",
"created_at": "2025-03-06T00:44:11.292Z",
"updated_at": "2025-03-06T02:04:10.581Z"
},
"message": "authentication data"
}