PKCE in Apex

// generate code verifier
final String codeVerifier = EncodingUtil.base64Encode(Crypto.generateAesKey(256));

// generate code challenge (sha-256 hash of verifier and then base64url encoded)
final Blob bCodeChallenge = Crypto.generateDigest('SHA-256', Blob.valueOf(codeVerifier));
final String codeChallengePre = EncodingUtil.base64Encode(bCodeChallenge);

// base64url escape
final String codeChallenge = codeChallengePre.replaceAll('[+]', '-').replaceAll('[/]', '_').replaceAll('[=]', '');

Published by

lekkim

Positive, competent, out-spoken, frank and customer focused architect and developer with a strong foundation in web, cloud and product development. I'm a strong advocate for API first and cloud based solutions and development. I have a knack for being able to communicate and present technically complicated matters in conference, customer and training settings. I've previously acted as team member and leader in a product organisation.

Leave a Reply

Your email address will not be published. Required fields are marked *