scaffoldeducation/jwt-manager-php

PHP library to manage JWT authentication

1.2.0 2021-03-18 17:15 UTC

This package is auto-updated.

Last update: 2024-09-19 01:09:06 UTC


README

PHP library to manage JWT authentication

Installation

Requires PHP 7.1.

The recommended way to install is through Composer.

composer require scaffoldeducation/jwt-manager-php

Migration

To execute migration on a Lumen system, you will need import JwtManagerServiceProvider in you application:

Open .\bootstrap\app.php and add this line: $app->register(JwtManager\JwtManagerServiceProvider::class);

You can custom blacklist table name at your .env file (default: oauth_jwt_blacklist):

OAUTH_TABLE_BLACKLIST=oauth_jwt_blacklist

Now execute on your terminal this command: php artisan migratre

Usage

Import this library in your application and use:

// expire and renew is seconds (900 = 15 minutes)
$jwt = new JwtManager(string $appSecret, string $context, int $expire, int $renew);

// generete a new token
$token = $jwt->generate(string $audience, string $subject, array $payload);

// to invalid this token, use:
$jwt->turnInvalid($token);

Sample

it's a good idea to look in the sample folder to understand how it works.

First verify if all dependencies is installed (if need anyelse)

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

and run

php sample/jwtManager-sample.php