Skip to content

Instantly share code, notes, and snippets.

@ashkanRmk
Created October 18, 2018 09:07
Show Gist options
  • Select an option

  • Save ashkanRmk/226ff51dd9f21cf1a2f1e7f64968342c to your computer and use it in GitHub Desktop.

Select an option

Save ashkanRmk/226ff51dd9f21cf1a2f1e7f64968342c to your computer and use it in GitHub Desktop.
function base64url_encode($plainText)
{
$base64 = base64_encode($plainText);
$base64 = trim($base64, "=");
$base64url = strtr($base64, '+/', '-_');
return ($base64url);
}
$random = bin2hex(openssl_random_pseudo_bytes(32));
$verifier = base64url_encode(pack('H*', $random));
$challenge = base64url_encode(pack('H*', hash('sha256', $verifier)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment