/// <summary> /// Gets the instance of <see cref="OpenIdConnectConfiguration"/> with the given certificate. /// </summary> /// <param name="cert">The certificate with the signing public keys.</param> /// <returns>The instance of <see cref="OpenIdConnectConfiguration"/>.</returns> private static OpenIdConnectConfiguration GetTestO365OpenIdConnectConfiguration(X509Certificate2 cert) { OpenIdConnectConfiguration config = new OpenIdConnectConfiguration(GetTestOpenIDConfiguration().ToString()); JObject jwk = CertificateHelper.ToJsonWebKey(cert); JsonWebKeySet jwks = new JsonWebKeySet(jwk.ToString()); foreach (SecurityKey key in jwks.GetSigningKeys()) { config.SigningKeys.Add(key); } return(config); }
public async Task TestValidToken() { var testCert = GetTestCert(); var openIdConfig = GetTestO365OpenIdConnectConfiguration(testCert); CancellationToken cancelToken; Mock <IConfigurationManager <OpenIdConnectConfiguration> > mockConfigManager = new Mock <IConfigurationManager <OpenIdConnectConfiguration> >(); mockConfigManager.Setup(cm => cm.GetConfigurationAsync(cancelToken)).ReturnsAsync(openIdConfig); ActionableMessageTokenValidator validator = new ActionableMessageTokenValidator(mockConfigManager.Object); string token = CertificateHelper.GenerateJsonWebToken(testCert, "*****@*****.**", "*****@*****.**", "https://api.contoso.com"); ActionableMessageTokenValidationResult result = await validator.ValidateTokenAsync(token, "https://api.contoso.com"); Assert.True(result.ValidationSucceeded); Assert.Equal("*****@*****.**", result.ActionPerformer); Assert.Equal("*****@*****.**", result.Sender); }