Skip to content

Instantly share code, notes, and snippets.

@diegosomar
Created June 19, 2020 23:57
Show Gist options
  • Save diegosomar/d6b9edde64ba8531af55d0cee5928ee3 to your computer and use it in GitHub Desktop.
Save diegosomar/d6b9edde64ba8531af55d0cee5928ee3 to your computer and use it in GitHub Desktop.
<?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