viloveul/auth

Viloveul auth with jwt.

v1.0.6 2019-04-18 08:08 UTC

This package is auto-updated.

Last update: 2024-04-18 20:37:44 UTC


README

make sure your php version > 7.0

composer require viloveul/auth

HOW

first you need to generate private key and public key

$ openssl genrsa -out private.pem -aes256 4096
$ openssl rsa -pubout -in private.pem -out public.pem

add this

require __DIR__ . '/vendor/autoload.php';

$auth = new Viloveul\Auth\Authentication($your_phrase);

$auth->setPrivateKey('private.pem');

$auth->setPublicKey('public.pem');

// create user data
$data = new Viloveul\Auth\UserData([
	'id' => 5,
	'name' => 'Viloveul',
	'email' => 'me@viloveul.com'
]);

// get token
$token = $auth->generate($data);
var_dump($token);

// check token
$auth->setToken($token);
$auth->authenticate();
var_dump($auth->getUser());