以下是一个示例代码,该代码中使用了 ADFS SSO 提供的身份验证 Token,并且使用正确的证书进行了签名:
private async void AuthenticateWithADFS()
{
var clientAssertionCertPfx = GetCertificate();
var authority = ConfigurationManager.AppSettings["ida:AADInstance"];
var clientId = ConfigurationManager.AppSettings["ida:ClientId"];
var clientAssertionCert = new X509Certificate2(clientAssertionCertPfx, "password");
string[] scopes = { "openid", "profile", "email" };
var cca = new ConfidentialClientApplication(clientId, authority, new ClientCredential(clientAssertionCert));
var authenticationResult = await cca.AcquireTokenForClientAsync(scopes);
// Use the authenticationResult.Token to call the API as necessary
}