Download the PHP package code16/machina without Composer
On this page you can find all versions of the php package code16/machina. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download code16/machina
More information about code16/machina
Files in code16/machina
Package machina
Short Description Machine to machine authentication for Laravel
License MIT
Informations about the package machina
Machina
This package is a wrapper around tymons\jwt-auth, aimed at providing a simple & flexible machine-to-machine authentication for Laravel 5.5+.
Installation
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 :
Then run this command, which will add a JWT_SECRET entry in your .env file:
Defining machine guard
In config/auth.php :
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 :
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
Authenticating and retrieving token
Send a POST request the /auth/login endpoint with client and secret as parameters :
If the credentials are correct, the API will return a JWT token that can be used to access protected routes.
Accessing protected routes
There is two ways of passing the token along the request :
-
Passing the token in the
authorizationheader with the following string format :Bearer <token> - Passing the token as a query parameter :
https://app.dev/protected?token=<token>
Implementing client applications
For your client applications, you can use our companion package, machina client.
All versions of machina with dependencies
illuminate/support Version ^11.0|^12.0|^13.0
php-open-source-saver/jwt-auth Version ^2.1