cli-microsoft365: Bug report: unable to login using certificate

Priority

(Medium) I’m annoyed but I’ll live

Description

When trying to login to CLI for Microsoft 365 using a certificate file, an error is thrown.

image

Steps to reproduce

  1. Create Entra ID app registration with certificate authentication
  2. Generate a certificate
  3. Run m365 login --authType certificate --certificateFile <path to file> --appId <app ID> --password <password> --tenant <tenant ID>

Expected results

CLI should read the certificate and retrieve a token.

Actual results

Error: Unparsed DER bytes remain after ASN.1 parsing.

Diagnostics

image

CLI for Microsoft 365 version

v7.4.0

nodejs version

v20.10.0

Operating system (environment)

Windows

Shell

PowerShell

cli doctor

No response

Additional Info

The certificate is definitely valid. I can log in using the base64 string of the certificate. I’m also able to log in using the certificate with password in PnP.PowerShell. It seems like something goes wrong when trying to read the certificate.

About this issue

  • Original URL
  • State: closed
  • Created 5 months ago
  • Reactions: 1
  • Comments: 17 (17 by maintainers)

Most upvoted comments

I’m using 2.3.0.

Just created a new certificate using the same command/options. This certificate works. Strange! The old certificate is still not working, yet I can authenticate with that one using PnP.PowerShell. Since a new certificate works, I think we can close this issue 🤷 Thanks!

Could very well be the certificate format @milanholemans. I use this script for it and it works all the time:

$name = "SomeName"
$password = ConvertTo-SecureString -String "some-password" -Force -AsPlainText
$cert = New-SelfSignedCertificate -NotBefore $(Get-Date).AddDays(-1) -NotAfter $(Get-Date).AddYears(1) -FriendlyName $name -CertStoreLocation cert:\CurrentUser\My -Subject "CN=$name" -KeyAlgorithm RSA -KeyLength 2048 -KeyExportPolicy Exportable
$cert | Export-Certificate -Type cer -FilePath "$PWD/$name.cer" -Force
$cert | Export-PfxCertificate -FilePath "$PWD/$name.pfx" -Password $password
$cert | Remove-Item

It creates the cert, exports it to the current folder and removes it from the cert store.