onza-me/backend_jwt

Template of laravel package for DomDa project.

dev-master 2021-10-28 12:41 UTC

This package is auto-updated.

Last update: 2024-09-28 19:09:27 UTC


README

Generating RSA keys

php artisan jwt:rsa:generate

By default command will create directory: storage/app/rsa, with files access_token_id_rsa and access_token_id_rsa.pub

access_token_id_rsa - Private key

access_token_id_rsa.pub - Public key

If you will run command again your old keys will renamed like this: access_token_id_rsa.1591959685.bak

Usage

Generate new AccessToken model

// Attributes: token, expires_at, refresh_token
use OnzaMe\JWT\Models\AccessToken;

$accessToken = new AccessToken(['super secret data'], ['test']);

Decode data

use OnzaMe\JWT\JWT;
use OnzaMe\JWT\RSAKeys;
use OnzaMe\JWT\Services\AccessTokenService;

$service = new AccessTokenService(new JWT(), new RSAKeys());

$mixedData = $service->decode("JWToken");

Environment variables

JWT_TOKEN_EXPIRES_IN - JWToken life in seconds, Default: 1800

JWT_REFRESH_TOKEN_EXPIRES_IN - JWToken for refresh life time in seconds, Default: 604800

JWT_USER_CLASS - Please set your User class if you wanna use JWTAuth middleware