Skip to content

Instantly share code, notes, and snippets.

@rbrayb
Created August 15, 2019 00:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbrayb/66e1652516aca85cad1b8417d0d2d227 to your computer and use it in GitHub Desktop.
Save rbrayb/66e1652516aca85cad1b8417d0d2d227 to your computer and use it in GitHub Desktop.
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