oralunal / scribe-auth
A Laravel middleware package that adds authentication protection to your Scribe API documentation.
Requires
- php: ^8.2
- knuckleswtf/scribe: ^5.0
- laravel/framework: ^12.0|^13.0
Requires (Dev)
- orchestra/testbench: ^10.0|^11.0
- phpunit/phpunit: ^11.5|^12.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
A Laravel middleware package that adds authentication protection to your Scribe API documentation. This package provides a simple way to secure your API documentation with basic authentication, ensuring that only authorized users can access your API documentation pages.
Requirements
- Scribe's
typeconfig should be set tolaravelin yourconfig/scribe.phpfile. - Scribe's
laravel->add_routesconfig should be set totruein yourconfig/scribe.phpfile.
Installation
- Install the package via Composer:
composer require oralunal/scribe-auth
- Add the
webandscribe.authmiddleware to yourconfig/scribe.phpfile:
'middleware' => [ // ... 'web', 'scribe.auth', ],
- Publish the configuration file:
php artisan vendor:publish --tag=scribe-auth-config
Configuration
The package comes with a config file (config/scribe_auth.php) where you can customize the following settings:
SCRIBE_AUTH_ENABLED: Enable/disable the middleware (Default:false)SCRIBE_AUTH_PASSWORD: Authentication password (Default: none). If it is missing or empty, the login is locked: every attempt is refused. A config file that you published before v1.2.0 still has the old123456789fallback: see Upgrading to v1.2.0.SCRIBE_AUTH_MAX_ATTEMPTS: Login attempts per minute for each user or IP address (Default:5)
Add the following environment variable to your .env file:
SCRIBE_AUTH_ENABLED=true SCRIBE_AUTH_PASSWORD=your_fantastic_password
Security
- Use different credentials in production
- Choose a strong password
- Keep your credentials secure
The login fails closed: when the configured password is missing or empty, every attempt is refused. A config file that you published before v1.2.0 still has a fallback value: see Upgrading to v1.2.0. The password is compared with hash_equals, and the session id is regenerated after a correct login.
Upgrading to v1.2.0
- A missing password now locks the login. Before v1.2.0, the package config used
123456789whenSCRIBE_AUTH_PASSWORDwas not set. SetSCRIBE_AUTH_PASSWORDbefore you upgrade if you use the default config. - Check your published config. If you published
config/scribe_auth.phpbefore v1.2.0, your copy still hasenv('SCRIBE_AUTH_PASSWORD', '123456789'), and your copy wins over the package config. Change that line toenv('SCRIBE_AUTH_PASSWORD')by hand.
Testing
composer install
composer test
License
This package is open-sourced software licensed under the MIT license.