Download the PHP package clystnet/laravel-jwt without Composer
On this page you can find all versions of the php package clystnet/laravel-jwt. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-jwt
Laravel JWT
This is a fork of the UniSharp/laravel-jwt package
Approach
If you pick Tymon JWTAuth
as your jwt solution in your project, when you try to refresh your token, the package will blacklist your exchanged token (assume your blacklist feature is enabled). So when your client faces a concurrency use case, your request might be rejected because that request is sent before your app renews jwt token returned by server. This package caches the refreshed jwt token in a short period to ensure your client side can get correct response even if your request carries an old token in a concurrency case.
Installation
-
Via Composer
- Add the Service Provider
In Lumen please use
PHPOpenSourceSaver\JWTAuth\Providers\LumenServiceProvider::class,
Next, also in the app.php config file, under the aliases array, you may want to add the JWTAuth facade.
Finally, you will want to publish the config using the following command:
Don't forget to set a secret key in the config file!
this will generate a new random key, which will be used to sign your tokens.
And you're done!
Usage
Open your config/auth.php
config file and in place of driver under any of your guards, just add the jwt-auth
as your driver and you're all set.
Make sure you also set provider
for the guard to communicate with your database.
Setup Guard Driver
Middleware Usage
Middleware protecting the route:
Middleware protecting the controller:
This middleware will automatically refresh jwt token if the existing one has been expired. The new refreshed jwt token will be carried to the response header:
Ahthorization
. The client side needs to replace your expired jwt token with the new one.
Note: The above example assumes you've setup a guard with the name api
whose driver is jwt-auth
in your config/auth.php
file as explained in "Setup Guard Driver" section above.
The following usage examples assume you've setup your default auth guard to the one which uses the
jwt-auth
driver.You can also explicitly define the guard before making calls to any of methods by just prefixing it with
Auth::guard('api')
.Example:
Auth::guard('api')->user()
Attempt To Authenticate And Return Token
Authenticate Once By ID
Authenticate Once By Credentials
Validate Credentials
Check User is Authenticated
Check User is a Guest
Logout Authenticated User
Generate JWT Auth Token By ID
Get Authenticated User
Once the user is authenticated via a middleware, You can access its details by doing:
You can also manually access user info using the token itself:
Get Authenticated User's ID
Refresh Expired Token
Though it's recommended you refresh using the middlewares provided with the package, but if you'd like, You can also do it manually with this method.
Refresh expired token passed in request:
Refresh passed expired token:
Invalidate Token
Invalidate token passed in request:
Invalidate token by setting one manually:
Get Token
Get Token Payload
This method will decode the token and return its raw payload.
Get Payload for the token passed in request:
Get Payload for the given token manually:
All versions of laravel-jwt with dependencies
illuminate/support Version ^5.6 | ^6.0 | ^7.0 | ^8.0 | ^9.0 | ^10.0 | ^11.0
php-open-source-saver/jwt-auth Version ^2.2 | ^2.4