Microsoft Office 365: The Certificate Does Not Have A Private Key

How to fix "The certificate does not have a private key"?

Issue Description: When using Application ID and Certificate authentication from Office 365 Scope, the following error is thrown when trying to authenticate

Full Error In Text:

RemoteException wrapping Microsoft-GraphServiceException: Code: generalExcepti0n

Message: An error occurred sending the request.

> RemoteException wrapping Microsoft.Identity.CIient.MsaICIientException: The certificate certificate does not have a private key.

at Microsoft.ldentity.ClientConfidentialCIientApplicationBuilder.WithCertificate(X509Certificate2 certificate)

at UiPathSharedAuthenticationMicrosoftServicesMsalLogonServiceGetBuilderFromCertificate(OAuthDataOptions oauth)

at UiPathShared.Authentication.MicrOSOft.Services.MsaILogonService.GetConfidentiaIAppIication(OAuthDataOptions oauth)

at UiPathSharedAuthenticationMicrosoftServicesMsalLogonService.AuthenticatelntemalAsync(OAuthDataOptions oauth,

CancellationToken cancellation Token)

Root Cause:

  1. The base64 representation of your certificate is incorrect
  2. The certificate wasn't properly created, therefore does not have a private key.


Resolution:

  1. The base64 representation of your certificate is incorrect
  2. To ensure that the conversion is done right, use the following VB expression to convert the .pfx certificate to base64
convert.ToBase64String(System.IO.File.ReadAllBytes(“YourCertPath"))

  1. The certificate was not properly created, therefore does not have a private key
  2. Check with the certificate publisher. Additionally, Create your own self-signed certificate to authenticate and check if the issue persists. (Ensure to also export the public certificate and its private key).