Api token authentication for laravel projects
exodusanto/laravel-concierge is a Laravel package for api token authentication for laravel projects.
It currently has 2 GitHub stars and 2.646 downloads on Packagist (latest version v0.6.0).
Install it with composer require exodusanto/laravel-concierge.
Discover more Laravel packages by exodusanto
or browse all Laravel packages to compare alternatives.
Last updated
Extend the base solution from Laravel with some new features
GET requestsYou can install the package via composer:
composer require exodusanto/laravel-concierge
Migrate your user table with api_token and api_token_refreshed_at.
Schema::table('users', function (Blueprint $table) {
$table->string('api_token')->nullable();
$table->timestamp('api_token_refreshed_at')->nullable();
});
This attribute is use to store the timestamp of api_token update
Add RefreshApiToken trait and RefreshApiTokenContract contract to your model
class User extends BaseUser implements RefreshApiTokenContract
{
use RefreshApiToken;
}
Publish concierge config
php artisan vendor:publish --tag=concierge-config
Use the same key to identify the right model in auth.providers and concierge.tokens_lifetime
// config/auth.php
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
]
// config/concierge.php
'tokens_lifetime' => [
'users' => 10800 // 3h
]
Append RefreshApiToken to your application web middleware group
// app/Http/Kernel.php
protected $middlewareGroups = [
'web' => [
...
\Exodusanto\Concierge\Http\Middleware\RefreshApiToken::class,
],
Concierge is shipped with a custom Blade directive, it will render the token of the authenticated user
@concierge
<!-- Rendered to -->
<script>
__CONCIERGE__ = { "api_token": "XXXXXXXXXXXX" }
</script>
@concierge($guard, $attributeName)
@concierge('other_guard', 'my_token')
<!-- Rendered to -->
<script>
<!-- Token of other_guard authenticated user -->
__CONCIERGE__ = { "my_token": "XXXXXXXXXXXX" }
</script>
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
This package was generated using the Laravel Package Boilerplate.