Igor-Lopes
A class to decode, verify and generate tokens with the php-jwt library
A class to decode, verify and generate tokens with the php-jwt library.
JSON Web Tokens are an easy way to authenticate an API. Unlikely in the traditional Server Session Authentication, the session data is stored only in the client side, reducing database queries, improving the backend performance and scalability.
composer require firebase/php-jwt
JWTAuth.php
in your file with require
or require_once
.Composer support will be available soon
$jwt = new JWTManager();
In order to generate a token, we have to pass the extra data that will be in the token, for example:
$token = $jwt-> encodeToken("admin");
$data = $jwt-> decodeToken($jwt);
The method decodeToken
will return a JSON:
Key | Description | Value |
---|---|---|
valid | Defines whether the token is valid or not | Boolean |
message | Description of the token verification result | String |
scope | Extra data in the token | String |
Examples of the returned JSON:
Success:
{"valid":true,"message":"Token is valid","scope":"admin"}
Error:
{"valid":false,"message":"Expired token"}
PHP JWT Library
Copyright (c) 2011, Neuman Vong
All rights reserved.
Issues, Pull requests and questions are very welcome.
This project is licensed under the [MIT License] (https://opensource.org/licenses/MIT) and the PHP JWT Library is licensed under [3-Clause BSD] (https://opensource.org/licenses/BSD-3-Clause).