Download the PHP package nivekaa/laravel-api-key without Composer
On this page you can find all versions of the php package nivekaa/laravel-api-key. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nivekaa/laravel-api-key
More information about nivekaa/laravel-api-key
Files in nivekaa/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 Auth
The initial core files of this package was cloned from ejarnutowski/laravel-api-key
Installation
Run composer require niveka/laravel-api-key
.
In your config/app.php
file, add the Laravel API Key service provider to the end of the providers
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-API-KEY: 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.