Created
November 10, 2017 19:59
-
-
Save jasonjoh/8a46f2d1ee028712a33cc537d2cecc75 to your computer and use it in GitHub Desktop.
GetSigningKeys
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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