daycry / jwt
JWT Token for Codeigniter 4
Installs: 4 293
Dependents: 4
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=7.4 || ^8.0
- lcobucci/jwt: ^4
Requires (Dev)
- codeigniter4/framework: ^4
- friendsofphp/php-cs-fixer: 3.6.*
- mikey179/vfsstream: ^1.6
- nexusphp/cs-config: ^3.3
- nexusphp/tachycardia: ^1.0
- phpstan/phpstan: ^1.7.1
- phpunit/phpunit: ^9.1
- rector/rector: 0.13.9
README
JWT
JWT for Codeigniter 4
Installation via composer
Use the package with composer install
> composer require daycry/jwt
Manual installation
Download this repo and then enable it by editing app/Config/Autoload.php and adding the Daycry\JWT namespace to the $psr4 array. For example, if you copied it into app/ThirdParty:
$psr4 = [ 'Config' => APPPATH . 'Config', APP_NAMESPACE => APPPATH, 'App' => APPPATH, 'Daycry\JWT' => APPPATH .'ThirdParty/JWT/src', ];
Configuration
Run command:
> php spark jwt:publish
This command will copy a config file to your app namespace.
Then you can adjust it to your needs. By default file will be present in app/Config/JWT.php
.
Usage Loading Library
<?php $library = new \Daycry\JWT\JWT(); $encode = $this->library->encode('hello');
If you want change attributes before controller call:
<?php $config = config('JWT'); $library = new \Daycry\JWT\JWT($config); $encode = $this->library->encode('hello'); $decode = $this->library->decode($encode); $decode->get('data');
By default it is saved in the data parameter, but it can be modified as follows
<?php $config = config('JWT'); $library = (new \Daycry\JWT\JWT($config))->setParamData('another'); $encode = $this->library->encode('hello'); $decode = $this->library->decode($encode); $decode->get('another');
If you want save an array data
<?php $config = config('JWT'); $library = (new \Daycry\JWT\JWT($config))->setParamData('another'); $encode = $this->library->encode(array( 'first' => '1', 'second' => '2' )); $decode = $this->library->decode($encode); \json_decode($decode->get('another'));
If you want to save the data array separately
<?php $config = config('JWT'); $library = (new \Daycry\JWT\JWT($config))->setSplitData(); $encode = $this->library->encode(array( 'first' => '1', 'second' => '2' )); $decode = $this->library->decode($encode); $decode->get('first'); $decode->get('second');