private static String calculateCodeVerifierHash(final String method, final String codeVerifier) { if ("plain".equalsIgnoreCase(method)) { return codeVerifier; } if ("S256".equalsIgnoreCase(method)) { val sha256 = DigestUtils.sha256(codeVerifier); return EncodingUtils.encodeUrlSafeBase64(sha256.getBytes(StandardCharsets.UTF_8)); } throw new CredentialsException("Code verification method is unrecognized: " + method); } }