How to do PKCE challenge in PHP

Getting ‘PKCE verification failed’ errors. How to generate a valid code challenge in PHP?

Answering own question, couresy of this post

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)));

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.