Overview
By default, Geni’s docs routes (UI, JSON and MCP) return 404 outside thelocal environment:
config/geni.php
local you have two ways to open the docs, and you can combine them:
- A
viewApiDocsgate: decide access with your own authorization logic. - Isolated docs credentials (
docs_auth): a username and password that are independent of your users.
The viewApiDocs Gate
Define the gate in a service provider:
app/Providers/AppServiceProvider.php
restrict_to_local enabled (the default), docs requests are handled as follows:
The gate receives the authenticated user, or
null for guests. User-based gates need a session, so add web to the docs middleware:
config/geni.php
Set
restrict_to_local to false to skip the environment and gate check entirely and rely only on docs_auth. When both are enabled, a request must pass both.Isolated Docs Credentials
Documentation authentication is completely decoupled from your application’s user table, database guards, and session cookies.Supported Modes
Geni supports two authentication modes:form: A standalone HTML login page matching the docs UI theme.basic: Browser-native HTTP Basic Authentication prompt.
Form-Based Authentication (Recommended)
Set the mode toform and configure credentials in your .env file:
.env
config/geni.php:
config/geni.php
How Form Auth Works
- Unauthenticated visitors accessing
/docs/apiare redirected to/docs/api/login. - A login screen matching the docs portal dark/light theme is presented.
- Submitting valid credentials creates an isolated session under the session key
geni_docs_auth_logged_in. - Unauthenticated requests to the JSON specification (
/docs/api.jsonor/docs/api/v1.json) return an HTTP 401 JSON response ({"message": "Unauthorized."}), rather than an HTML redirect, preventing broken JSON parsers. - A logout button in the sidebar footer ends the docs session. Logging in and logging out both regenerate the session id, and logout also rotates the CSRF token.
HTTP Basic Authentication
If you prefer browser-native authentication without session cookies:.env
Authorization: Basic ... headers will receive an HTTP 401 response with a WWW-Authenticate: Basic realm="API Documentation" header.
How Credentials Are Checked
- Setting only one of the two values fails closed, so a blank value can never match a blank submission.
- Username and password are compared in constant time (
hash_equals), and both are always checked, without short-circuiting.
Disabling Authentication
To remove the credentials gate (e.g. for open public developer portals), leave bothusername and password blank or set them to null:
.env
local, the docs still follow restrict_to_local and the viewApiDocs gate. To make them fully public, define a gate that always passes or set restrict_to_local to false.