Skip to content

Instantly share code, notes, and snippets.

@jasonjoh
Created November 10, 2017 19:59
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 jasonjoh/8a46f2d1ee028712a33cc537d2cecc75 to your computer and use it in GitHub Desktop.
Save jasonjoh/8a46f2d1ee028712a33cc537d2cecc75 to your computer and use it in GitHub Desktop.
GetSigningKeys
private List<SecurityKey> GetSigningKeys()
{
// TODO: Implement a cache of signing keys with the auth metadata URL
// as an index
// When requests come in to validate a token, check if you already have cached signing keys
// for that URL
// Load tokens
var webClient = new WebClient();
var authMetaData = JsonConvert.DeserializeObject<ExchangeAuthMetadata>(webClient.DownloadString(AppContext.MetadataUrl));
// Build list of signing keys
List<SecurityKey> signingKeys = new List<SecurityKey>();
foreach (ExchangeKey key in authMetaData.Keys)
{
if (string.Compare(key.KeyInfo.Thumbprint, Header.X5t, StringComparison.InvariantCulture) == 0 &&
string.Compare(key.KeyValue.Type, "x509Certificate", StringComparison.InvariantCulture) == 0)
{
signingKeys.Add(new X509SecurityKey(new X509Certificate2(Encoding.UTF8.GetBytes(key.KeyValue.Value))));
}
}
return signingKeys;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment