PHPackages                             code16/machina - 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. code16/machina

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

code16/machina
==============

Machine to machine authentication for Laravel

v1.9.0(1mo ago)31.2k11MITPHPPHP 8.3.\*|8.4.\*|8.5.\*CI failing

Since Jan 23Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/code16/machina)[ Packagist](https://packagist.org/packages/code16/machina)[ RSS](/packages/code16-machina/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (8)Versions (15)Used By (1)

Machina
=======

[](#machina)

This package is a wrapper around `tymons\jwt-auth`, aimed at providing a simple &amp; flexible machine-to-machine authentication for Laravel 5.5+.

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

[](#installation)

```
    composer require code16/machina

```

Configuration
-------------

[](#configuration)

If you want to customize some default options like the prefix used for `/login` and `/refresh` endpoints by the package, you can publish it to your application folder :

```
    php artisan config:publish code16/machina

```

Then run this command, which will add a `JWT_SECRET` entry in your `.env` file:

```
    php artisan jwt:secret

```

### Defining machine guard

[](#defining-machine-guard)

In `config/auth.php` :

```
    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

        'machina' => [
            'driver' => 'machina',
            'provider' => Api\ClientRepository::class,
        ],
    ],
```

### Creating a `ClientRepository` class

[](#creating-a-clientrepository-class)

This package does not come with an opinionated way of retrieving clients, but instead provides a very simple way to adapt it to your application, by providing a class implementing `Code16\Machina\ClientRepositoryInterface`.

Example :

```
    namespace App;

    use Code16\Machina\ClientRepositoryInterface;

    class ClientRepository implements ClientRepositoryInterface
    {
        public function findByKey($key)
        {
            return User::find($key);
        }

        public function findByCredentials($client, $secret)
        {
            return User::where('id', $client)->where('secret', $secret)->first();
        }

    }
```

Note that here we used the standard `App\User` model DB to identify our client, but you can use whichever model / fields you like.

Protecting routes
-----------------

[](#protecting-routes)

```
    Route::get('protected', 'ApiController@index')->middleware('auth:machina');

```

Authenticating and retrieving token
-----------------------------------

[](#authenticating-and-retrieving-token)

Send a POST request the `/auth/login` endpoint with `client` and `secret` as parameters :

```
    {
        client : "1",
        secret : "x7jfajleug64hggi"
    }

```

If the credentials are correct, the API will return a JWT token that can be used to access protected routes.

Accessing protected routes
--------------------------

[](#accessing-protected-routes)

There is two ways of passing the token along the request :

- Passing the token in the `authorization` header with the following string format : `Bearer `
- Passing the token as a query parameter : `https://app.dev/protected?token=`

Implementing client applications
--------------------------------

[](#implementing-client-applications)

For your client applications, you can use our companion package, [machina client](https://github.com/code16/machina-client).

###  Health Score

57

—

FairBetter than 98% of packages

Maintenance94

Actively maintained with recent releases

Popularity22

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~227 days

Recently: every ~281 days

Total

11

Last Release

31d ago

PHP version history (4 changes)v1.4.0PHP ^8.1

v1.5.0PHP ^8.1|^8.2

v1.6.0PHP ^8.1|^8.2|^8.3

v1.9.0PHP 8.3.\*|8.4.\*|8.5.\*

### Community

Maintainers

![](https://www.gravatar.com/avatar/f97dcdc942d25d5b5720b790d5f28e6accc6f05370cf5a6b52b78abc60c29e57?d=identicon)[code16](/maintainers/code16)

---

Top Contributors

[![PatrickePatate](https://avatars.githubusercontent.com/u/16721134?v=4)](https://github.com/PatrickePatate "PatrickePatate (20 commits)")[![RemiCollin](https://avatars.githubusercontent.com/u/9589616?v=4)](https://github.com/RemiCollin "RemiCollin (19 commits)")[![dvlpp](https://avatars.githubusercontent.com/u/973325?v=4)](https://github.com/dvlpp "dvlpp (11 commits)")[![smknstd](https://avatars.githubusercontent.com/u/2412608?v=4)](https://github.com/smknstd "smknstd (6 commits)")[![PierreBillaud](https://avatars.githubusercontent.com/u/43741101?v=4)](https://github.com/PierreBillaud "PierreBillaud (4 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/code16-machina/health.svg)

```
[![Health](https://phpackages.com/badges/code16-machina/health.svg)](https://phpackages.com/packages/code16-machina)
```

###  Alternatives

[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[illuminate/auth

The Illuminate Auth package.

9327.3M1.0k](/packages/illuminate-auth)[olssonm/l5-very-basic-auth

Laravel stateless HTTP basic auth without the need for a database

1662.5M1](/packages/olssonm-l5-very-basic-auth)[scaler-tech/laravel-saml2

SAML2 Service Provider integration for Laravel applications, based on OneLogin toolkit

2737.5k](/packages/scaler-tech-laravel-saml2)[truckersmp/steam-socialite

Laravel Socialite provider for Steam OpenID.

1516.7k](/packages/truckersmp-steam-socialite)[pschocke/laravel-telegram-login-widget

Easily integrate Telegrams login widget into your Laravel application to send Telegram messages

1610.4k](/packages/pschocke-laravel-telegram-login-widget)

PHPackages © 2026

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