PHPackages                             uogsoe/basic-api-token-middleware - 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. [API Development](/categories/api)
4. /
5. uogsoe/basic-api-token-middleware

ActiveLibrary[API Development](/categories/api)

uogsoe/basic-api-token-middleware
=================================

Very basic API key middleware for Laravel

1.1.1(8y ago)115.5k↓53.6%6[1 PRs](https://github.com/UoGSoE/api-token-middleware/pulls)MITPHP

Since Apr 19Pushed 7y ago1 watchersCompare

[ Source](https://github.com/UoGSoE/api-token-middleware)[ Packagist](https://packagist.org/packages/uogsoe/basic-api-token-middleware)[ RSS](/packages/uogsoe-basic-api-token-middleware/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (1)Versions (5)Used By (0)

Basic API key middleware for Laravel
====================================

[](#basic-api-key-middleware-for-laravel)

This is a simple key-based middleware for Laravel. It suited our common use-case of internal apps which need access to other internal apps (machine-to-machine) without the hassles of oauth etc.

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

[](#installation)

You should be able to pull it in using composer :

```
composer require uogsoe/basic-api-token-middleware

```

Then you have to publish the database migration and ApiKey model :

```
php artisan vendor:publish

```

And pick `UoGSoE\ApiTokenMiddleware\ApiTokenServiceProvider` from the list. Then run the migration :

```
php artisan migrate

```

Usage
-----

[](#usage)

First of all you create a token for the consuming 'service' (eg, the remote client) :

```
php artisan apitoken:create testservice

```

That will create the token and show it to you. You need to take note of the token as your client will have to use it to access the routes.

Now in your `routes/api.php` file you can use the middleware to wrap endpoints :

```
Route::group(['middleware' => 'apitoken:testservice'], function () {
    Route::get('/hello', function () {
        return 'hello';
    });
});

```

If you try and access that route without passing the token you will get a 401 response :

```
curl -kv https://my-project.test/api/hello
...
HTTP/2 401
{"message":"Unauthorized"}

```

So pass the token you created above and it should let you through :

```
curl -kv https://my-project.test/api/hello?api_token=jT7ryt28gi3YCvgE4WvluO1uVcb0ndVx
...
HTTP/2 200
hello

```

You can pass the token in various ways, like a GET param as above, a bearer token header or as part of the JSON body. Eg:

```
$this->withHeaders([
    'Authorization' => 'Bearer '.$tokenString,
])->get('https://my-project.test/api/hello');

$this->json('POST', 'https://my-project.test/api/hello', ['api_token' => $token]);

$this->call('POST', 'https://my-project.test/api/hello', ['api_token' => $token]);

```

You can use multiple service token names with a route if you want to seperate your api controls too :

```
Route::group(['middleware' => 'apitoken:testservice,anotherservice'], function () {
    Route::get('/hello', function () {
        return 'hello';
    });
});

```

There are a few other artisan commands available to help manage the tokens :

```
php artisan apitoken:list -- lists all current tokens
php artisan apitoken:regenerate -- create a new token for a given service
php artisan apitoken:delete -- deletes a given service token

```

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

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

2998d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5472be37b2cbedfa6c905bb674cb5780378cf2adcfc47befe01ad7bb4d14f734?d=identicon)[ohnotnow](/maintainers/ohnotnow)

---

Top Contributors

[![ohnotnow](https://avatars.githubusercontent.com/u/6471843?v=4)](https://github.com/ohnotnow "ohnotnow (8 commits)")[![SaxJ](https://avatars.githubusercontent.com/u/1689439?v=4)](https://github.com/SaxJ "SaxJ (1 commits)")

---

Tags

apilaravelmiddlewaretoken

### Embed Badge

![Health badge](/badges/uogsoe-basic-api-token-middleware/health.svg)

```
[![Health](https://phpackages.com/badges/uogsoe-basic-api-token-middleware/health.svg)](https://phpackages.com/packages/uogsoe-basic-api-token-middleware)
```

###  Alternatives

[exsyst/swagger

A php library to manipulate Swagger specifications

35916.4M7](/packages/exsyst-swagger)[hubspot/api-client

Hubspot API client

24016.2M20](/packages/hubspot-api-client)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

172445.0k15](/packages/pocketmine-bedrock-protocol)[botman/driver-telegram

Telegram driver for BotMan

93459.5k6](/packages/botman-driver-telegram)

PHPackages © 2026

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