PHPackages                             victorybiz/laravel-api-key - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. victorybiz/laravel-api-key

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

victorybiz/laravel-api-key
==========================

Authorize requests to your Laravel application with API keys

v1.0.3(6y ago)3471MITPHPPHP &gt;=5.5.9

Since Feb 17Pushed 6y ago1 watchersCompare

[ Source](https://github.com/victorybiz/laravel-api-key)[ Packagist](https://packagist.org/packages/victorybiz/laravel-api-key)[ RSS](/packages/victorybiz-laravel-api-key/feed)WikiDiscussions master Synced yesterday

READMEChangelog (4)DependenciesVersions (5)Used By (0)

Laravel API Key Authorization
=============================

[](#laravel-api-key-authorization)

[![GitHub release](https://camo.githubusercontent.com/5f44cc562f1a00fc788f2b4330c7b4da420bc7d661d24a92f325b242e8f8fec9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f766963746f727962697a2f6c61726176656c2d6170692d6b65792e737667)](https://packagist.org/packages/victorybiz/laravel-api-key)[![Software License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](LICENSE)[![Build Status](https://camo.githubusercontent.com/b56e3099d70fdb94f1ffc348c016fac8e3d4f0919230e3b885e63041707c8557/68747470733a2f2f7472617669732d63692e6f72672f766963746f727962697a2f6c61726176656c2d6170692d6b65792e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/victorybiz/laravel-api-key)[![Packagist](https://camo.githubusercontent.com/cc3ab5d01640f1be6a0db7980a4390a83d197f09e0d5afd8edc11c62323ca93a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f766963746f727962697a2f6c61726176656c2d6170692d6b65792e737667)](https://packagist.org/packages/victorybiz/laravel-api-key)

API Key Authorization for Laravel application.

The initial core files of this package was cloned from [*`ejarnutowski/laravel-api-key`*](https://github.com/ejarnutowski/laravel-api-key)

Installation
------------

[](#installation)

Install using composer, from the command line run:

```
$ composer require victorybiz/laravel-api-key
```

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 &gt;= 5.5** you can skip this step and go to [**`publish and run the migrations`**](https://github.com/victorybiz/laravel-api-key#publish-the-migration-files)

> If you use **Laravel &lt; 5.5**, you need to register the service provider with the application. Open up `config/app.php` and locate the `providers` key, add the Laravel API Key service provider to the end of the `providers` array.

```
'providers' => [
    ...
    Victorybiz\LaravelApiKey\Providers\ApiKeyServiceProvider::class,

],
```

#### Publish the migration files

[](#publish-the-migration-files)

```
$ php artisan vendor:publish

```

#### Run the migrations

[](#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
-------------

[](#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.

```
$ php artisan apikey:generate app1

// API key created
// Name: app1
// Key: 0ZdNlr7LrQocaqz74k6usQsOsqhqSIaUarSTf8mxnHuQVh9CvKAfpUy94VvBmFMq
```

Deactivate a key using `php artisan apikey:deactivate {name}`.

```
$ php artisan apikey:deactivate app1

// Deactivated key: app1
```

Activate a key using `php artisan apikey:activate {name}`.

```
$ php artisan apikey:activate app1

// Activated key: app1
```

Delete a key. You'll be asked to confirm. Keys are [soft-deleted](https://laravel.com/docs/eloquent#soft-deleting) for record keeping.

```
$ php artisan apikey:delete app1

// Are you sure you want to delete API key 'app1'? (yes/no) [no]:
// > yes

// Deleted key: app1
```

List all keys. The -D or --deleted flag includes deleted keys

```
$ php artisan apikey:list -D

// +----------+----+-------------+---------------------+------------------------------------------------------------------+
// | Name     | ID | Status      | Status Date         | Key                                                              |
// +----------+----+-------------+---------------------+------------------------------------------------------------------+
// | app1     | 5  | deleted     | 2017-11-03 13:54:51 | 0ZdNlr7LrQocaqz74k6usQsOsqhqSIaUarSTf8mxnHuQVh9CvKAfpUy94VvBmFMq |
// | app2     | 1  | deleted     | 2017-11-02 22:34:28 | KuKMQbgZPv0PRC6GqCMlDQ7fgdamsVY75FrQvHfoIbw4gBaG5UX0wfk6dugKxrtW |
// | app3     | 3  | deactivated | 2017-11-02 23:12:34 | IrDlc7rSCvUzpZpW8jfhWaH235vJAqFwyzVWpoD0SLGzOimA6hcwqMvy4Nz6Hntn |
// | app4     | 2  | active      | 2017-11-02 22:48:13 | KZEl4Y2HMuL013xvg6Teaa7zHPJhGy1TDhr2zWzlQCqTxqTzyPTcOV6fIQZVTIU3 |
// +----------+----+-------------+---------------------+------------------------------------------------------------------+
```

Usage
-----

[](#usage)

### Implementing Authorization

[](#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](https://laravel.com/docs/middleware) in the Laravel Docs.

Route example

```
Route::get('api/user/1', function () {
    //
})->middleware('auth.apikey');
```

Controller example

```
class UserController extends Controller
{
    /**
     * Instantiate a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth.apikey');
    }
}
```

### Authorizing Requests

[](#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
---------------------

[](#unauthorized-requests)

Requests that do not pass authorization will receive an HTTP `401` Status Code with the following response

```
{
    "status": false,
    "message": "Unauthorized endpoint request.",
}
```

Event History
-------------

[](#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
-------

[](#license)

The Laravel API Key package is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 64.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

4

Last Release

2276d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/10cf31ece5d47446da1fde10df50e84c0d2bbd0052f0f688e89590d9b8909f5a?d=identicon)[victorybiz](/maintainers/victorybiz)

---

Top Contributors

[![victorybiz](https://avatars.githubusercontent.com/u/8276466?v=4)](https://github.com/victorybiz "victorybiz (11 commits)")[![ejarnutowski](https://avatars.githubusercontent.com/u/753408?v=4)](https://github.com/ejarnutowski "ejarnutowski (3 commits)")[![ipimpat](https://avatars.githubusercontent.com/u/450038?v=4)](https://github.com/ipimpat "ipimpat (2 commits)")[![Clayboy](https://avatars.githubusercontent.com/u/1386860?v=4)](https://github.com/Clayboy "Clayboy (1 commits)")

---

Tags

apilaravelAuthenticationauthorizationapi-keylaravel api key

### Embed Badge

![Health badge](/badges/victorybiz-laravel-api-key/health.svg)

```
[![Health](https://phpackages.com/badges/victorybiz-laravel-api-key/health.svg)](https://phpackages.com/packages/victorybiz-laravel-api-key)
```

###  Alternatives

[ejarnutowski/laravel-api-key

Authorize requests to your Laravel application with API keys

157441.1k1](/packages/ejarnutowski-laravel-api-key)[auth0/login

Auth0 Laravel SDK. Straight-forward and tested methods for implementing authentication, and accessing Auth0's Management API endpoints.

2745.0M3](/packages/auth0-login)[hasinhayder/tyro

Tyro - The ultimate Authentication, Authorization, and Role &amp; Privilege Management solution for Laravel 12 &amp; 13

6712.1k2](/packages/hasinhayder-tyro)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
