Authentication
The Zoo Arcadia API uses session-based authentication that integrates with the main web application’s authentication system. Most API endpoints are public and do not require authentication, while certain administrative endpoints require an active user session.Authentication Method
The API uses session-based authentication with the following characteristics:- Session cookies are used to maintain authentication state
- Sessions are shared between the web application and API
- Session duration is 11 hours (39,600 seconds)
- Secure cookie parameters prevent common attacks
The API does not use API keys or OAuth tokens. It relies on the same session management as the web application.
Public vs. Authenticated Endpoints
Public Endpoints (No Authentication Required)
The following API endpoints are publicly accessible without authentication:GET /api- API informationGET /api/animals- List all animalsGET /api/animals/show?id={id}- Get animal detailsGET /api/habitats- List all habitatsGET /api/habitats/show?id={id}- Get habitat detailsGET /api/services- List zoo servicesGET /api/schedules- Get zoo schedulesGET /api/testimonials- Get validated testimonials
Authenticated Endpoints
Certain endpoints require authentication and an active session:- Administrative endpoints (resource management)
- User-specific data endpoints
- Content management endpoints
How to Authenticate
To authenticate with the API, you need to establish a session by logging in through the web application.Step 1: Login
Send a POST request to the login endpoint with valid credentials:The
-c cookies.txt flag saves the session cookie to a file for subsequent requests.Step 2: Make Authenticated Requests
Include the session cookie in subsequent API requests:Browser-Based Authentication
When making API requests from a web browser:- Users must first log in through the web interface at
/auth/pages/login - The browser automatically includes session cookies in API requests
- No additional authentication headers are needed
Session Management
Session Duration
Sessions have the following characteristics:- Lifetime: 11 hours (39,600 seconds)
- Timeout: Sessions expire after 11 hours of inactivity
- Auto-renewal: Each authenticated request updates the last activity timestamp
Session Expiration
When a session expires:- Users are automatically redirected to
/auth/pages/login?msg=session_expired - Session data is completely destroyed
- Session cookies are removed
- A new login is required to continue
Session Security
Sessions are configured with secure parameters:- HttpOnly: Prevents JavaScript from accessing session cookies (XSS protection)
- Secure: Cookies are only sent over HTTPS in production
- SameSite: Lax mode allows navigation from external links while preventing CSRF attacks
CSRF Protection
For state-changing requests (POST, PUT, DELETE), CSRF protection may be required:CSRF Token Usage
- CSRF tokens are included in web forms
- The same session-based CSRF protection applies to API requests
- For POST requests, include the CSRF token if required by the endpoint
Most public GET endpoints do not require CSRF tokens. CSRF protection is primarily enforced on state-changing operations.
Authentication Errors
Common Authentication Issues
| Error | Cause | Solution |
|---|---|---|
| Redirect to login | No active session | Log in through /auth/pages/login |
| Session expired | Inactive for 11+ hours | Re-authenticate |
| Invalid session | Corrupted session data | Clear cookies and log in again |
| Unauthorized | Insufficient permissions | Verify user role and permissions |
Handling Redirects
API requests to authenticated endpoints without a valid session will result in:- HTTP redirect (302) to
/auth/pages/login - Or JSON error response with 401 status code (depending on endpoint)
Best Practices
For Public Endpoints
- No authentication needed for read-only operations
- Simply make GET requests to public endpoints
- No need to manage sessions or cookies
For Authenticated Endpoints
- Establish Session: Log in through the web interface first
- Include Cookies: Always include session cookies in requests
- Handle Expiration: Implement logic to re-authenticate when sessions expire
- Use HTTPS: Always use HTTPS in production for security
- Monitor Activity: Keep sessions active by making periodic requests
Security Recommendations
Next Steps
API Overview
Return to API overview and available endpoints
Animals Endpoint
Start making requests to the animals API