PHP code example of arrow-web-sol / laravel-jwt-auth

1. Go to this page and download the library: Download arrow-web-sol/laravel-jwt-auth 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/ */

    

arrow-web-sol / laravel-jwt-auth example snippets


Route::middleware('auth:jwt')->get('/user', [UserController::class, 'index']);

	    'defaults' => [
        	'guard' => 'jwt',

//if jwt isn't your default guard
$this->actingAs($user, 'jwt');

//if jwt is your default guard
$this->actingAs($user);

//NOTE: You need the private key set in config to do this for asymetric signatures
$jwtConfig = $this->app()->make(\Arrow\JwtAuth\Contracts\JwtConfiguration::class);

$token = $jwtConfig
    ->builder()
    ->issuedBy('https://arrow-web.dev')
    ->permittedFor('https://example.com')
    ->identifiedBy(Str::random(12))
    ->issuedAt(now()->toDateTimeImmutable())
    ->canOnlyBeUsedAfter(now()->toDateTimeImmutable())
    ->expiresAt(now()->addHour()->toDateTimeImmutable())
    ->withClaim('claim-name', 'claim-value')
    ->getToken($jwtConfig->signer(), $jwtConfig()->signingKey());

$this->withToken($token->toString())
    ->getJson('/user')
    ->assertSuccessful();