Download the PHP package victorybiz/laravel-api-key without Composer
On this page you can find all versions of the php package victorybiz/laravel-api-key. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download victorybiz/laravel-api-key
More information about victorybiz/laravel-api-key
Files in victorybiz/laravel-api-key
Package laravel-api-key
Short Description Authorize requests to your Laravel application with API keys
License MIT
Informations about the package laravel-api-key
Laravel API Key Authorization
API Key Authorization for Laravel application.
The initial core files of this package was cloned from ejarnutowski/laravel-api-key
Installation
Install using composer, from the command line run:
Alternatively, you can add "victorybiz/laravel-api-key": "^1.0"
to your composer.json file's require
section and
then you'll then need to run composer install
or composer update
to download it and have the autoloader updated.
If you use Laravel >= 5.5 you can skip this step and go to
publish and run the migrations
If you use Laravel < 5.5, you need to register the service provider with the application. Open up
config/app.php
and locate theproviders
key, add the Laravel API Key service provider to the end of theproviders
array.
Publish the migration files
$ php artisan vendor:publish
Run the migrations
$ php artisan migrate
3 new database tables will be created:
- api_keys
- api_key_access_events
- api_key_admin_events
Managing Keys
Generate a new key using php artisan apikey:generate {name}
. The name argument is the name of your API key. All new keys are active by default.
Deactivate a key using php artisan apikey:deactivate {name}
.
Activate a key using php artisan apikey:activate {name}
.
Delete a key. You'll be asked to confirm. Keys are soft-deleted for record keeping.
List all keys. The -D or --deleted flag includes deleted keys
Usage
Implementing Authorization
A new auth.apikey
route middleware has been registered for you to use in your routes or controllers. Below are examples on how to use middleware, but for detailed information, check out Middleware in the Laravel Docs.
Route example
Controller example
Authorizing Requests
In order to pass the auth.apikey
middleware, requests must include an X-Authorization
header as part of the request, with its value being an active API key.
X-Authorization: KuKMQbgZPv0PRC6GqCMlDQ7fgdamsVY75FrQvHfoIbw4gBaG5UX0wfk6dugKxrtW
Unauthorized Requests
Requests that do not pass authorization will receive an HTTP 401
Status Code with the following response
Event History
All API requests that pass authorization are logged in the api_key_access_events
table. A record is created for each request with the following information:
- api_key_id
- ip_address
- url
- created_at
- updated_at
Any time an API key is generated, activated, deactivated, or deleted, a record is logged in the api_key_admin_events
table. Each record contains the following information:
- api_key_id
- ip_address
- event
- created_at
- updated_at
License
The Laravel API Key package is open-sourced software licensed under the MIT license.