Skip to content

Instantly share code, notes, and snippets.

@rbrayb
Created Aug 15, 2019
Embed
What would you like to do?
Using Proof Key for Code Exchange (PKCE) in ADFS for Windows Server 2019
using IdentityModel;
using System;
using System.Security.Cryptography;
using System.Text;
namespace ADFS_PKCE_Core
{
class Program
{
// https://www.scottbrady91.com/OpenID-Connect/ASPNET-Core-using-Proof-Key-for-Code-Exchange-PKCE
static void Main(string[] args)
{
//var codeVerifier = CryptoRandom.CreateUniqueId(32);
var codeVerifier = "1qaz2wsx3edc4rfv5tgb6yhn1234567890qwertyuiop";
string codeChallenge;
using (var sha256 = SHA256.Create())
{
var challengeBytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(codeVerifier));
codeChallenge = Base64Url.Encode(challengeBytes);
}
Console.WriteLine("codeVerifier " + codeVerifier + "\n");
Console.WriteLine("codeChallenge " + codeChallenge + "\n");
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment