PHPackages                             cable8mm/auth-by-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/auth-by-key

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

cable8mm/auth-by-key
====================

Authorize requests to your Laravel application with API keys

v2.2.0(1mo ago)161MITPHPPHP ^8.2CI passing

Since Nov 18Pushed 1mo ago1 watchersCompare

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

READMEChangelog (3)Dependencies (15)Versions (5)Used By (0)

Auth By Key
===========

[](#auth-by-key)

[![code-style](https://github.com/cable8mm/auth-by-key/actions/workflows/code-style.yml/badge.svg)](https://github.com/cable8mm/auth-by-key/actions/workflows/code-style.yml)[![run-tests](https://github.com/cable8mm/auth-by-key/actions/workflows/run-tests.yml/badge.svg)](https://github.com/cable8mm/auth-by-key/actions/workflows/run-tests.yml)[![Packagist Version](https://camo.githubusercontent.com/44fe008ac5456ccc3ef509ca0c1fcdfab2bba838cfce3fdbc5ad0840e210b67d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6361626c65386d6d2f617574682d62792d6b6579)](https://camo.githubusercontent.com/44fe008ac5456ccc3ef509ca0c1fcdfab2bba838cfce3fdbc5ad0840e210b67d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6361626c65386d6d2f617574682d62792d6b6579)[![Packagist Downloads](https://camo.githubusercontent.com/850c8f89498c1c056048ea18e76cce5f65027e59765ac9a4877deef3b2b06561/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6361626c65386d6d2f617574682d62792d6b6579)](https://camo.githubusercontent.com/850c8f89498c1c056048ea18e76cce5f65027e59765ac9a4877deef3b2b06561/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6361626c65386d6d2f617574682d62792d6b6579)[![Packagist Dependency Version](https://camo.githubusercontent.com/6d05a42c1c3c8b49749595afaef7e6848901565c9d9b2571babd84ef1ea63df4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f6361626c65386d6d2f617574682d62792d6b65792f706870)](https://camo.githubusercontent.com/6d05a42c1c3c8b49749595afaef7e6848901565c9d9b2571babd84ef1ea63df4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f6361626c65386d6d2f617574682d62792d6b65792f706870)[![Packagist Stars](https://camo.githubusercontent.com/725fc820a3f6e41391535c030de40a95869d97c7c8b404bf7620579bfdf9418f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f73746172732f6361626c65386d6d2f617574682d62792d6b6579)](https://camo.githubusercontent.com/725fc820a3f6e41391535c030de40a95869d97c7c8b404bf7620579bfdf9418f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f73746172732f6361626c65386d6d2f617574682d62792d6b6579)[![Packagist License](https://camo.githubusercontent.com/147fbecc006899ab8093aee230ff0607471d3d8a239a0dbcca184eb6252b4920/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6361626c65386d6d2f617574682d62792d6b6579)](https://camo.githubusercontent.com/147fbecc006899ab8093aee230ff0607471d3d8a239a0dbcca184eb6252b4920/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6361626c65386d6d2f617574682d62792d6b6579)

We are also able to use Laravel's first-party libraries for authorization, but it might not be lightweight. Yes, as a user Eloquent model, this can help with the problem. Only requests that pass through the 'auth-by-key' layer can proceed to the next stage through Laravel request.

We have provided the API Documentation on the web. For more information, please visit  ❤️

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

[](#installation)

Run `composer require cable8mm/auth-by-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=auth-by-key-nova
```

If you will typically need to overwrite,

```
php artisan vendor:publish --tag=auth-by-key-nova --force
```

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

[](#fix-coding-style)

```
composer lint
```

Test
----

[](#test)

```
composer test
```

### Test Coverage

[](#test-coverage)

This package includes comprehensive test coverage. To run tests with coverage report:

```
# Run tests with HTML coverage report
composer test -- --coverage-html coverage

# View coverage report
open coverage/index.html
```

### Coverage Configuration

[](#coverage-configuration)

The test suite is configured with code coverage tracking in `phpunit.xml.dist`. The `src` directory is included in coverage analysis.

### Writing Tests

[](#writing-tests)

When contributing to this package, please ensure:

1. All new features include corresponding tests
2. Tests cover both success and failure scenarios
3. Event dispatches are verified using Laravel's event faking
4. Console commands test validation, execution, and output

### CI/CD Integration

[](#cicd-integration)

Tests are automatically run on GitHub Actions for every pull request. The CI pipeline includes:

- Code style checks with Laravel Pint
- Full test suite execution
- Code coverage reporting

License
-------

[](#license)

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

###  Health Score

45

—

FairBetter than 91% of packages

Maintenance92

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 82.4% 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 ~321 days

Total

4

Last Release

39d ago

PHP version history (2 changes)v2.1.0PHP ^8.0

v2.2.0PHP ^8.2

### 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 (28 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

apikey-authenticationauthorizationcomposer-packagelaravelphp8apilaravelAuthenticationauthorizationapi-key

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/cable8mm-auth-by-key/health.svg)

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.4M354](/packages/psalm-plugin-laravel)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.6k31.8M160](/packages/laravel-cashier)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

79227.1M227](/packages/laravel-mcp)[api-platform/laravel

API Platform support for Laravel

58190.1k21](/packages/api-platform-laravel)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9922.4M146](/packages/roots-acorn)[forjedio/inertia-table

Backend-driven dynamic tables for Laravel + Inertia.js

272.0k](/packages/forjedio-inertia-table)

PHPackages © 2026

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