Downloads
Stars
Version
$ composer require silverbullet/api-token-laravel
Add service provider to the providers
array in config/app.php
file:
'providers' => [
...
Silverbullet\ApiTokenLaravel\Providers\ApiTokenServiceProvider::class
],
Publish the migration file:
php artisan vendor:publish --provider="Silverbullet\ApiTokenLaravel\Providers\ApiTokenServiceProvider"
Run the migration:
php artisan migrate
$ php artisan api-token:generate {name} {code?}
$ php artisan api-token:list
$ php artisan api-token:delete {id}
Use middleware with the key apitoken.auth:{code}
on your Larave route. Example:
Route::get('partner-products', function() {
//
})->middleware('apitoken.auth:{service1}');
You can also pass multiple parameters for the {code}
(e.g. apitoken.auth{service1,service2}
). This feature enables you to authorize the service that is going to use your API.
To pass the middleware, you must include Authorization
header as a part of your request.
Authorization: Basic {api_token_goes_here}
401
: Unauthenticated
This error code means you do not have the valid token.
403
: Unauthorized
This error code means you do have a valid token but not the permission to access the API you are trying to access.
The MIT License (MIT). Please see License File for more information.