tymon/jwt-auth
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
illuminate/auth | v10.48.10 | - | MIT | prod | |
illuminate/console | v10.48.10 | - | MIT | prod dev | |
illuminate/contracts | v10.48.10 | - | MIT | prod | |
illuminate/database | v10.38.1 | 334.64 kB | MIT | prod dev | |
illuminate/http | v10.48.10 | - | MIT | prod | |
illuminate/support | v10.48.10 | - | MIT | prod | |
lcobucci/jwt | 4.3.0 | - | BSD-3-Clause | prod | |
nesbot/carbon | 2.72.3 | 766.72 kB | MIT | prod dev |
Tymon/JWT-auth is a specialized composer package that provides JSON Web Token Authentication for Laravel and Lumen. It is a powerful tool that lets developers add a layer of security to their web application by facilitating user authentication through JWTs. With a robust variety of features, tymon/jwt-auth is designed to seamlessly integrate with Laravel, one of the most popular PHP frameworks.
To use the tymon/jwt-auth package, first, you need to install it via composer by running the composer require tymon/jwt-auth
command in your project directory. Once installed, you may need to publish the package configuration using php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\LaravelServiceProvider"
. This command publishes the JWT configuration file to your Laravel configuration folder.
Here's a very simple usage example:
use Tymon\JWTAuth\Facades\JWTAuth;
try {
if (! $token = JWTAuth::attempt($credentials)) {
return response()->json(['error' => 'invalid_credentials'], 400);
}
} catch (JWTException $e) {
return response()->json(['error' => 'could_not_create_token'], 500);
}
return response()->json(compact('token'));
In this example, you would replace $credentials
with an array of user credentials like ['email' => 'user1@example.com', 'password' => 'password']
.
When the user credentials are authenticated successfully, a JWT token is returned. If the credentials are invalid, a JSON response with an error message is returned.
Remember, the package greatly simplifies the process of issuing and validating JWTs. It is flexible enough to fit into most of the typical JWT-based authentication setups.
The documentation for tymon/jwt-auth can be found at jwt-auth.com. This extensive online guide provides a comprehensive breakdown of all the methods and functionalities incorporated into the package, equipped with illustrative examples and clear instructions that ease the understanding of the tool, guiding the developer through the process of successful implementation into their projects.