Created
October 23, 2020 10:20
-
-
Save vigikaran/31cfa341cf710aaa43856ef9f8c29ab9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Helpers; | |
use \Firebase\JWT\JWT; | |
use Illuminate\Support\Str; | |
class Utils | |
{ | |
public static function generateToken($payload){ | |
$tokenId = (string) Str::uuid(); | |
$issuedAt = time(); | |
$notBefore = $issuedAt; | |
$expire = $issuedAt + config('jwt.expire'); | |
$serverName = config('app.domain'); | |
$data = [ | |
'iat' => $issuedAt, | |
'jti' => $tokenId, | |
'iss' => $serverName, | |
'nbf' => $notBefore, | |
'exp' => $expire, | |
'data' => $payload | |
]; | |
$secretKey = config('jwt.key'); | |
$jwt = JWT::encode($data,$secretKey,'HS512'); | |
return $jwt; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment