PHP code example of iqbalatma / laravel-jwt-authentication
1. Go to this page and download the library: Download iqbalatma/laravel-jwt-authentication 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/ */
iqbalatma / laravel-jwt-authentication example snippets
#token ttl is token lifetime on (seconds)
#so the token will life and valid until ttl finish
return [
'algo' => env('JWT_ALGO', 'HS256'),
"jwt_private_key" => env("JWT_PRIVATE_KEY", null),
"jwt_public_key" => env("JWT_PUBLIC_KEY", null),
"jwt_passphrase" => env("JWT_PASSPHRASE", null),
'secret' => env('JWT_SECRET', null),
'access_token_ttl' => env('JWT_TTL', 60 * 60),
'refresh_token_ttl' => env('JWT_REFRESH_TTL', 60 * 60 * 24 * 7),
];
use Illuminate\Support\Facades\Auth;
$credentials = [
"email" => "[email protected]",
"password" => "admin"
];
#this attempt method will return boolean when user validation success
Auth::attempt($credentials);
#passing true on second parameter to get return array of access_token and refresh_token
Auth::attempt($credentials, true);
use Illuminate\Support\Facades\Auth;
Auth::logout();
use Illuminate\Support\Facades\Auth;
Auth::refreshToken(Auth::user());
use Illuminate\Support\Facades\Auth;
use App\Models\User;
$user = User::find(1);
Auth::login($user);
use Illuminate\Support\Facades\Auth;
use App\Models\User;
$credentials = [
"email" => "[email protected]",
"password" => "admin"
];
Auth::attempt($credentials);
Auth::getAccessToken();
Auth::getRefreshToken();
use Iqbalatma\LaravelJwtAuthentication\Services\IssuedTokenService;
#use to get all issued token
IssuedTokenService::getAllToken();
#use to get all issued refresh token
IssuedTokenService::getAllTokenRefresh()
#use to get all issued access token
IssuedTokenService::getAllTokenAccess();
#use to revoke refresh token by user agent string name
IssuedTokenService::revokeTokenRefreshByUserAgent('user-agent-name');
#use to revoke access token by user agent string name
IssuedTokenService::revokeTokenAccessByUserAgent('user-agent-name');
#use to revoke both access and refresh token by user agent string name
IssuedTokenService::revokeTokenByUserAgent('user-agent-name');
#use to revoke all token
IssuedTokenService::revokeAllToken();
#use to revoke all token but current token
IssuedTokenService::revokeAllTokenOnOtherUserAgent();