Skip to content

jpmgoncalves12/jwt-manager-php-lib-jwk

Repository files navigation

JWT Manager PHP

PRs Welcome

PHP library to manage JWT authentication

Installation

Release 4.0.0 Requires PHP 7.4

Release 3.0.0 Requires PHP 7.3

Release 2.0.0 Requires PHP 7.2

Release 1.0.0 Requires PHP 7.1

The recommended way to install is through Composer.

composer require not-empty/jwt-manager-php-lib

Usage

Generating a token

use JwtManager\JwtManager;
$secret = '77682b9441bb7daa7a1fa6eb7522b689';
$context = 'test';
$expire = 30;
$renew = 10;
$jwtManager = new JwtManager(
    $secret,
    $context,
    $expire,
    $renew
);
$tokenGenerated = $jwtManager->generate('test');
var_dump($tokenGenerated);

Dedoce the token and return the data

$result = $jwtManager->decodePayload($tokenGenerated);
var_dump($result);

Verify if token is valid

$result = $jwtManager->isValid($tokenGenerated);
var_dump($result);

Check if a token is on time

$result = $jwtManager->isOnTime($tokenGenerated);
var_dump($result);

Get the expiration time of a token

$result = $jwtManager->getexpire($tokenGenerated);
var_dump($result);

Check if need to refresh a token

$result = $jwtManager->tokenNeedToRefresh($tokenGenerated);
var_dump($result);

if you want an environment to run or test it, you can build and install dependences like this

docker build --build-arg PHP_VERSION=7.4.33-cli -t not-empty/jwt-manager-php-lib:php74 -f contrib/Dockerfile .

Access the container

docker run -v ${PWD}/:/var/www/html -it not-empty/jwt-manager-php-lib:php74 bash

Verify if all dependencies is installed

composer install --no-dev --prefer-dist

and run

php sample/jwt-manager-sample.php

Development

Want to contribute? Great!

The project using a simple code. Make a change in your file and be careful with your updates! Any new code will only be accepted with all validations.

To ensure that the entire project is fine:

First you need to building a correct environment to install all dependences

docker build --build-arg PHP_VERSION=7.4.33-cli -t not-empty/jwt-manager-php-lib:php74 -f contrib/Dockerfile .

Access the container

docker run -v ${PWD}/:/var/www/html -it not-empty/jwt-manager-php-lib:php74 bash

Install all dependences

composer install --dev --prefer-dist

Run all validations

composer check

Not Empty Foundation - Free codes, full minds

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published