cesg/jwt-token-guard

Laravel simple JWT token guard

Installs: 1 485

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/cesg/jwt-token-guard

v0.5.0 2023-01-25 11:43 UTC

This package is auto-updated.

Last update: 2025-10-25 17:49:46 UTC


README

Laravel simple JWT token guard

Install

composer require cesg/jwt-token-guard

Configure

Configure the auth driver

'api' => [
    'driver' => 'jwt',
    'provider' => 'users',
    'key' => env('JWT_KEY', \md5(env('APP_NAME'))),
],

Example secret key

openssl rand -hex 64

Usage

Javascript

const token = '';
axios.defaults.headers.common['Authorization'] = `Bearer ${token}`;

Laravel

protected function authenticated(Request $request, $user)
{
    $jwt = JWT::encode([
        'sub' => $user->getAuthIdentifier(),
        'iss' => config('app.name'),
        'iat' => now()->timestamp,
    ], config('auth.guards.api.key'));

    session(\compact('jwt'));
}