authentication – Unable to connect to SharePoint Online via CLI with the help of a certificate

I try to authenticate with SharePoint Online using the command prompt and certificate instead of the user name and password.

I have read their official documentation here.

The command to log in with the help of a certificate is as follows: spo connection --authType certificate --certificateFile /Users/user/dev/localhost.pfx --thumbprint 47C4885736C624E90491F32B98855AA8A7562AF1

I have followed all the necessary steps such as:

  1. Creation of Azure AD App,

  2. Download the certificate on Azure AD,

  3. and define the environment variables.

and when i try to connect, the following error appears constantly:

SelfSignedJwt: ERROR: Can not sign JWT. This is probably due to an invalid certificate.

I do not know where the root cause of the problem is, but I guess this is due to the way I generated the certificate. The documentation did not provide any information on how to generate the certificate.

I have generated my certificate with the help of the following command in PowerShell:

New-SelfSignedCertificate -Subject "CN = CertSample" -CertStoreLocation "Cert:  CurrentUser  My" -KeyExportPolicy Exportable -KeySpec Signature -NotAfter (Get-Date) .AddYears (2)