How to generate Code Verifier and COde challenge in PKCE?
To generate a Code Verifier and Code Challenge (PKCE) in OutSystems 11 you’ll typically use a combination of random string generation and SHA‑256 + Base64URL encoding. OutSystems doesn’t have a built‑in PKCE helper, but you can build it easily with existing functions / CryptoAPI.
PKCE (RFC 7636) expects:
[A-Z] [a-z] [0-9] "-" "." "_" "~"
BASE64URL( SHA256( code_verifier ) )
code_challenge_method = "S256"
Below is an approach you can implement in OutSystems:
Create a server action GenerateCodeVerifier:
GenerateCodeVerifier
Chars
Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~"
Length
Random()
Substr(Chars, Index, 1)
Verifier
Result: Verifier is your code_verifier.
If you already have a crypto‑random function exposed (e.g. from CryptoAPI), use that to avoid predictable sequences.
Create a server action GenerateCodeChallenge with input CodeVerifier (Text) and output CodeChallenge (Text).
GenerateCodeChallenge
CodeVerifier
CodeChallenge
Implementation outline using CryptoAPI:
Hash with SHA‑256
Use CryptoAPI’s SHA‑256 function (or ComputeMac if you expose SHA256 hash in an extension):
Binary = TextToBinaryData(CodeVerifier)
HashBinary
Base64 encode the hash
HashBase64 = BinaryToBase64(HashBinary)
This gives you standard Base64 (with +, /, and possibly = padding).
+
/
=
Convert Base64 to Base64URL (PKCE requirement)
Create another helper action Base64ToBase64Url:
Base64ToBase64Url
Input: HashBase64 (Text) Output: Base64Url (Text)
HashBase64
Base64Url
Base64Url = Replace(Replace(HashBase64, "+", "-"), "/", "_")
Right(Base64Url, 1) = "="
Base64Url = Left(Base64Url, Length(Base64Url) - 1)
Set CodeChallenge = Base64Url.
CodeChallenge = Base64Url
Now you have a PKCE‑compliant code_challenge for code_challenge_method = "S256".
code_verifier
code_challenge
If you describe which components (CryptoAPI version or your own extension) you are already using, I can map this to exact OutSystems actions and data types (BinaryData vs Text).