Skip to content

Instantly share code, notes, and snippets.

@vigikaran
Created October 23, 2020 10:20
Show Gist options
  • Save vigikaran/31cfa341cf710aaa43856ef9f8c29ab9 to your computer and use it in GitHub Desktop.
Save vigikaran/31cfa341cf710aaa43856ef9f8c29ab9 to your computer and use it in GitHub Desktop.
<?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