Created
May 29, 2018 20:45
-
-
Save johannesl/a61de9c639832397aed7f0fecb4e64c8 to your computer and use it in GitHub Desktop.
JSON Web Token without third-party dependencies
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 | |
function jwt_hs256_encode( $payload, $secret ) { | |
$headers = array( 'alg' => 'HS256', 'typ' => 'JWT' ); | |
$parts[] = base64url_encode( json_encode( $headers, JSON_FORCE_OBJECT ) ); | |
$parts[] = base64url_encode( json_encode( $payload, JSON_FORCE_OBJECT ) ); | |
$signature = hash_hmac( 'SHA256', $parts[0] .'.'. $parts[1], $secret, true ); | |
$parts[] = base64url_encode( $signature ); | |
return implode( '.', $parts ); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment