guilhermetome / jwt
A simple jwt class
1.0.1
2020-06-20 14:03 UTC
Requires
- php: ^7.2
- ext-json: *
This package is auto-updated.
Last update: 2024-08-20 11:59:47 UTC
README
This project is just a simple JWT class to add to your project and can be configured using contants.
Summary
Prerequisites
- PHP >= 7.2
- Composer
Installing
You can clone the project with this command:
- Clone repository:
git clone https://github.com/GuilhermeTome/jwt
- Install in your project:
composer require guilhermetome/jwt
How to use
- Only follow the docs.
Declare the jwt key
- In you application you need to create a const like this:
<?php
// the key of the application
define('JWT_SECRET', 'mysecret');
// the hash of the jwt
define('JWT_HASH', 'sha256');
// the alg to put in header
define('JWT_ALG', 'HS256');
Generate the jwt key
- @param array
- @return string
<?php
use GuilhermeTome\Jwt;
echo Jwt::encode([
'user' => 'Guilherme',
'email' => 'email@gmail.com',
'pass' => 'MyPassword'
]);
Decode the jwt key
- @param string
- @return array|false
<?php
use GuilhermeTome\Jwt;
echo Jwt::decode($key);
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate.
License
This project is licensed under the MIT Licence - see the MIT Licence for more details