Created
June 19, 2020 23:57
-
-
Save diegosomar/d6b9edde64ba8531af55d0cee5928ee3 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 | |
$key = '###############'; | |
$exp = ( new DateTime( "now" ) )->getTimestamp() + 120; | |
$header = [ | |
'typ' => 'JWT', | |
'alg' => 'HS256' | |
]; | |
$header = json_encode( $header ); | |
$header = base64url_encode( $header ); | |
$payload = [ | |
'iss' => '###############', | |
'exp' => $exp, | |
]; | |
$payload = json_encode( $payload ); | |
$payload = base64url_encode( $payload ); | |
$signature = hash_hmac( 'sha256', "{$header}.{$payload}", $key, true ); | |
$signature = base64url_encode( $signature ); | |
$token = "{$header}.{$payload}.{$signature}"; | |
return $token; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment