PHP code example of roundly-consulting / jwt-for-laravel

1. Go to this page and download the library: Download roundly-consulting/jwt-for-laravel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

roundly-consulting / jwt-for-laravel example snippets


'guards' => [
    'api' => ['driver' => 'jwt', 'provider' => 'users'],   // drop the provider to build a TokenUser from the claims alone
],

use RoundlyConsulting\Jwt\Facades\Jwt;
use RoundlyConsulting\Jwt\UserTokens\AccessTokenRequest;

$issued = Jwt::mintAccessToken(
    AccessTokenRequest::for($user->id)
        ->email($user->email, verified: true)
        ->permissions('posts.view', 'posts.edit')
);

$claims = Jwt::verify($issued->token);   // RS256, iss and aud pinned
$claims->string('sub');                  // "42"

Jwt::logout($issued);                    // denylist the jti until it expires

Route::middleware('auth:api')->get('/me', fn () => ['id' => auth()->id()]);
bash
composer jwt:generate-keys   # issuer apps: writes storage/jwt-private.key + storage/jwt-public.pem