Package Data | |
---|---|
Maintainer Username: | nobelatunje |
Maintainer Contact: | nobelatunje001@gmail.com (Ademuyiwa Adetunji) |
Package Create Date: | 2022-08-25 |
Package Last Update: | 2022-11-11 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2025-01-24 15:00:06 |
Package Statistics | |
---|---|
Total Downloads: | 3 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 8 |
Total Watchers: | 1 |
Total Forks: | 4 |
Total Open Issues: | 0 |
A simple JSON Web Token Authentication Library built on top of lcobucci/jwt for Laravel and Lumen.
It uses Asymmetric Algorithm using a private key for signature creation and a public key for verification. This means that it's fine to distribute your public key. However, the private key should remain secret.
Via composer
composer require nobelatunje/jwt
Install the package
php artisan jwt:install
Generate private and public keys
php artisan jwt:generate
Modify the jwtconfig.php in your config file as necessary and add your app's Policies if necessary.
Change the route driver in your auth.php config file to jwt.
'guards' => [
'custom_guard' => [
'driver' => 'jwt',
'provider' => 'users',
],
],
Route::middleware('auth:custom_guard')->get('/user', function (Request $request) {
return $request->user();
});
//if you set jwt as driver for your api guard
Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});
// Generate a token for the user if the credentials are valid
$token = Auth::attempt($credentials);
// Get the currently authenticated user
$user = Auth::user();