I’m trying to authenticate to an Azure AD Application using ClientCertificateCredential (in C#):
using Azure.Identity;
var credential = new ClientCertificateCredential("TenantId", "AppId", @"pathtocert.pfx");
on the application, I had configured the certificate’s SNI as a trusted certificated:
"trustedCertificateSubjects": [
{
"authorityId": "auth id ...",
"subjectName": "cert subject name",
"revokedCertificateIdentifiers": []
}
]
I had validated that all the values and configurations. Yet, I keep encountering the following error:
Azure.Identity.AuthenticationFailedException
HResult=0x80131500
Message=ClientCertificateCredential authentication failed: A configuration issue is preventing authentication – check the error message from the server for details. You can modify the configuration in the application registration portal. See https://aka.ms/msal-net-invalid-client for details. Original exception: AADSTS700027: The certificate with identifier used to sign the client assertion is not registered on application. [Reason – The key was not found., Thumbprint of key used by client: ‘<the correct current thumbprint>’, Please visit the Azure Portal, Graph Explorer or directly use MS Graph to see configured keys for app Id ‘<app Id>’. Review the documentation at https://docs.microsoft.com/en-us/graph/deployments to determine the corresponding service endpoint and https://docs.microsoft.com/en-us/graph/api/application-get?view=graph-rest-1.0&tabs=http to build a query request URL, such as ‘https://graph.microsoft.com/beta/applications/<App Id>’]. Alternatively, SNI may be configured on the app. Please ensure that client assertion is being sent with the x5c claim in the JWT header using MSAL’s WithSendX5C() method so that Azure Active Directory can validate the certificate being used.
I have checked all the provided links as well as other documents, none were helpful in resolving this issue. Any insights or direction to resolve this issue?
2
Answers
Found the solution: [FEATURE REQ] DefaultAzureCredential should send x5c claim for app authentication
Code Example (which worked successfully for me):
The error usually occurs, if the
.cer
certificate is not uploaded in the Azure AD Application Certificates and Secrets blade or if the.pfx
cert is not present in the machine where the code is running.I got the same error, when I dint upload any certificate in the Azure AD Application Certificates and Secrets blade:
Hence to resolve the error, upload the
.cer
certificate in the Certificates and Secrets blade:Manifest looks like below:
Make sure that the
.pfx
certificate exists in the machine where the code is running:Now for sample, I used the below code to generate the access token to authenticate the application:
Access token generated successfully: