A Base64Url encoded string of the SHA256 hash of the code_verifier.
echo code_challenge=$(printf %s "${code_verifier}" | openssl dgst -sha256 -binary | base64 | sed 's/+/-/g; s/\//_/g; s/=//g';)
/// <summary>
/// Creates a SHA256 hash of the specified input.
/// </summary>
/// <param name="input">The input.</param>
/// <returns>A hash</returns>
public static string ToSha256(this string input)
{
using (var sha = SHA256.Create())
{
var bytes = Encoding.UTF8.GetBytes(input);
var hash = sha.ComputeHash(bytes);
return Convert.ToBase64String(hash);
}
}
PKCE requires a code verifier. This is a cryptographically random string using the characters A-Z, a-z, 0-9, and the punctuation characters -._~ (hyphen, period, underscore, and tilde), between 43 and 128 characters long.
The code_verifier is held on to by the client and passed on a back channel during final code exchange. To initiate PKCE flow, during the auth-link phase, the following parameters must be supplied
curl -X POST \
-d grant_type=authorization_code \
-d client_id=${client_id} \
-d redirect_uri=${redirect_uri} \
-d code=${code} \
-d code_verifier=${code_verifier}
https://auth.truelayer.com/connect/token
export LC_CTYPE=C # this may be needed on Mac OSX to set expected locale
code_verifier=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 64)
More