PHPackages                             cable8mm/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. cable8mm/laravel-api-key

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

cable8mm/laravel-api-key
========================

Authorize requests to your Laravel application with API keys

v2.1.0(2y ago)011MITPHPPHP ^8.0

Since Nov 14Pushed 2y agoCompare

[ Source](https://github.com/cable8mm/laravel-api-key)[ Packagist](https://packagist.org/packages/cable8mm/laravel-api-key)[ RSS](/packages/cable8mm-laravel-api-key/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)Dependencies (7)Versions (10)Used By (0)

Laravel API Key Auth
====================

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

[![Build](https://github.com/cable8mm/laravel-api-key/actions/workflows/build.yml/badge.svg)](https://github.com/cable8mm/laravel-api-key/actions/workflows/build.yml)[![PHP Linting (Pint)](https://github.com/cable8mm/laravel-api-key/actions/workflows/coding-style-php.yml/badge.svg)](https://github.com/cable8mm/laravel-api-key/actions/workflows/coding-style-php.yml)[![Latest Stable Version](https://camo.githubusercontent.com/c045d8b7f2f85cd2b0750bc9a1095f179e33dcc479d17230b26e936b571f0a13/687474703a2f2f706f7365722e707567782e6f72672f6361626c65386d6d2f6c61726176656c2d6170692d6b65792f76)](https://packagist.org/packages/cable8mm/laravel-api-key)[![Total Downloads](https://camo.githubusercontent.com/9ed6c994687477f1ff26bc68847a8e5df79bf802d5930dc176187c3fab518b38/687474703a2f2f706f7365722e707567782e6f72672f6361626c65386d6d2f6c61726176656c2d6170692d6b65792f646f776e6c6f616473)](https://packagist.org/packages/cable8mm/laravel-api-key)[![Latest Unstable Version](https://camo.githubusercontent.com/13ac5180781383612c138ba6db235eb0d1b79aacac92294539ebcc6157e28986/687474703a2f2f706f7365722e707567782e6f72672f6361626c65386d6d2f6c61726176656c2d6170692d6b65792f762f756e737461626c65)](https://packagist.org/packages/cable8mm/laravel-api-key)[![License](https://camo.githubusercontent.com/b82752cd55947299325218b7eb20f883d0ea8f03a7dbe45a56fe9a541a46d963/687474703a2f2f706f7365722e707567782e6f72672f6361626c65386d6d2f6c61726176656c2d6170692d6b65792f6c6963656e7365)](https://packagist.org/packages/cable8mm/laravel-api-key)[![PHP Version Require](https://camo.githubusercontent.com/fc00f122d317723e2b3711872392cf657c085e671ae1e72056dca24edb298818/687474703a2f2f706f7365722e707567782e6f72672f6361626c65386d6d2f6c61726176656c2d6170692d6b65792f726571756972652f706870)](https://packagist.org/packages/cable8mm/laravel-api-key)

This repository was transferred to  then it was archived.

본 레포지토리는  로 이동되었고, 아카이브 되었습니다.

This version is a [fork](https://github.com/ejarnutowski/laravel-api-key).

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

[](#installation)

Run `composer require cable8mm/laravel-api-key`.

Run the migrations

```
$ php artisan migrate

```

1 new database tables will be created:

- api\_keys

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

```
{
    "errors": [
        {
            "message": "Unauthorized"
        }
    ]
}
```

Laravel Nova
------------

[](#laravel-nova)

Publish the nova resource file

```
php artisan vendor:publish --tag=laravel-api-key-nova
```

If you will typically need to overwrite,

```
php artisan vendor:publish --tag=laravel-api-key-nova --force
```

Fix coding style
----------------

[](#fix-coding-style)

```
composer lint
```

Test
----

[](#test)

```
composer test
```

License
-------

[](#license)

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

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 80% 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

7

Last Release

913d ago

Major Versions

v1.0.5 → v2.0.02023-11-15

### Community

Maintainers

![](https://www.gravatar.com/avatar/c910c874a0263a18f9f976273054cd45faa3ffbcba7891992f4ab52d0656dd93?d=identicon)[Sam Lee](/maintainers/Sam%20Lee)

---

Top Contributors

[![cable8mm](https://avatars.githubusercontent.com/u/2672043?v=4)](https://github.com/cable8mm "cable8mm (24 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-key

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[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)[ejarnutowski/laravel-api-key

Authorize requests to your Laravel application with API keys

157441.1k1](/packages/ejarnutowski-laravel-api-key)[hasinhayder/tyro

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

6712.1k2](/packages/hasinhayder-tyro)[casbin/laravel-authz

An authorization library that supports access control models like ACL, RBAC, ABAC in Laravel.

324339.9k4](/packages/casbin-laravel-authz)

PHPackages © 2026

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