I am new to Azure, and am trying a very basic scenario: locally authenticate to a registered app using a certificate credential.
The code is as follows:
public async Task<QueueClient> GetQueueClientWithSdkWithCertificateCredentials(string storageAccountName, string queueName, string tenantId, string clientId, string certificateBase64Str)
{
var certificateCredentials = new ClientCertificateCredential(tenantId, clientId, new X509Certificate2(Convert.FromBase64String(certificateBase64Str)));
var queueClient = new QueueClient(new Uri($"https://{storageAccountName}.queue.core.windows.net/{queueName}"), certificateCredentials);
var createQueueResponse = await queueClient.CreateAsync();
if (createQueueResponse.IsError)
{
throw new Exception($"Error in creating queue: [{createQueueResponse}]");
}
return queueClient;
}
queueClient.CreateAsync is failing with error
Azure.Identity.AuthenticationFailedException: 'ClientCertificateCredential authentication failed: The certificate certificate does not have a private key.
My setup is:
- I have created myself the certificate - using openssl as follows:
.\openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -days 120 -nodes -subj "/C=XX/ST=MyDistrict/L=MyTown/O=MyCompany/OU=MyOrg/CN=MyCertificate" - I then convert the certificate (cert.pem) to a pfx file so I can properly install it on Windows (checking the "export private key" checkbox so the key icon shows when double clicking on the certificate to see its details).
- I also make sure it is installed under Trusted Root Certification Authorities, just in case.
- So certificate is ultimately installed in my windows local store and looks like

- I then upload the cert.pem file to Azure, under my registered app's Certificates & Secrets screen.
- Then I go to my registered app's Manifests screen, and take the certificate base 64 representation I should be using in the Azure SDK API ("value" prop)

Doing all this - returns the error mentioned above. What is meant by "The certificate certificate does not have a private key" ? I mean, the certificate installed locally does show the key at the bottom - which indicates it DOES have the private key ?
What I am missing ?
Created a Microsoft Entra ID application and uploaded the certificate:
Exported the PFX certificate in the local machine:
The error "The certificate does not have a private key" usually occurs if you don't pass the private key.
To resolve the error, pass the private key and the certificate path when making use of client certificate authentication.
Modify the code like below to create the Queue using client certificate authentication:
Queue got created successfully:
In the Portal: