pnp / pnp/cli-microsoft365

Bug report: login doesn't work when using a certificate path in `m365 setup`

Open
#6,642 4 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug keep-open needs research
Dominant language
TypeScript
Stars
1.5k
Forks
413
Avg merge
5d 6h
Merged PRs (30d)
21

Description

Priority

(Low) Something is a little off

Description

When using the steps in m365 setup and using a path for my certificate file, i can't login using m365 login. I get the error Cannot read PKCS#12 PFX. ASN.1 object is not an PKCS#12 PFX.

When using m365 login --authType certificate --appId [appid] --tenant [tenant] --certificateFile C:\Users\Nico\Documents\DevOps\cli.pfx --password [password], it works like a charm. (notice that this.connection.certificate is not the path in this case

Image

Steps to reproduce
  • use m365 setup with the following steps

Image

  • use m365 login (added some extra logging)

Image

Expected results

I would expect that i get logged in 😄

Actual results

getting an error Cannot read PKCS#12 PFX. ASN.1 object is not an PKCS#12 PFX. because it tries to decode the path (const pemObjs = pem.decode(cert);, where cert is the path instead of the base64-encoded string

Diagnostics

m365 login --debug
Executing command login with options {"options":{"output":"text","debug":true,"verbose":false,"cloud":"Public"}}
Executing command as 'Custom PnP CLI for Microsoft 365', appId: [appId], tenantId: [tenantId]
Logging out from Microsoft 365...
Signing in to Microsoft 365...
No token found for resource https://graph.microsoft.com.
Retrieving new access token using certificate...
Error:
<ref *1> Error: Cannot read PKCS#12 PFX. ASN.1 object is not an PKCS#12 PFX.
at p12.pkcs12FromAsn1 (C:\Users\Nico\Documents\DevOps\cli-microsoft365\node_modules\node-forge\lib\pkcs12.js:329:17)
at Auth.ensureAccessTokenWithCertificate (file:///C:/Users/Nico/Documents/DevOps/cli-microsoft365/dist/Auth.js:408:38)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Auth.ensureAccessToken (file:///C:/Users/Nico/Documents/DevOps/cli-microsoft365/dist/Auth.js:188:26)
at async LoginCommand.ensureAccessToken (file:///C:/Users/Nico/Documents/DevOps/cli-microsoft365/dist/m365/commands/login.js:139:13)
at async LoginCommand.login (file:///C:/Users/Nico/Documents/DevOps/cli-microsoft365/dist/m365/commands/login.js:196:9)
at async LoginCommand.commandAction (file:///C:/Users/Nico/Documents/DevOps/cli-microsoft365/dist/m365/commands/login.js:77:13)
at async LoginCommand.action (file:///C:/Users/Nico/Documents/DevOps/cli-microsoft365/dist/m365/commands/login.js:91:9)
at async Object.executeCommand (file:///C:/Users/Nico/Documents/DevOps/cli-microsoft365/dist/cli/cli.js:250:9)
at async Object.execute (file:///C:/Users/Nico/Documents/DevOps/cli-microsoft365/dist/cli/cli.js:199:9) {
errors: [Circular *1]
}

Timings:
api: 0ms
core: 12.5103ms
command: 383.9408ms
options: 0.1646ms
total: 397.8491ms
validation: 1.5923ms

CLI for Microsoft 365 version

v10.5.0

nodejs version

v20.11.1

Operating system (environment)

Windows

Shell

PowerShell

cli doctor

authMode : certificate
cliConfig : {"copyDeviceCodeToClipboard":true,"autoOpenLinksInBrowser":true,"output":"text","printErrorsAsPlainText":true,"prompt":true,"showHelpOnFailure":true,"helpMode":"options","authType":"certificate","clientId":[clientId],"tenantId":[tenantId],"clientSecret":"","clientCertificateFile":"C:\Users\Nico\Documents\DevOps\cli.pfx","clientCertificatePassword":[clientCertificatePassword]}
cliEntraAppId : [cliEntraAppId ]
cliEntraAppTenant: single
cliEnvironment :
cliVersion : 10.5.0
nodeVersion : v20.11.1
os : {"platform":"win32","version":"Windows 11 Pro","release":"10.0.26100"}
roles : []
scopes : {}

Additional Info

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The failure reaches Auth.ensureAccessTokenWithCertificate in dist/Auth.js; start there and trace the certificate value produced by m365 setup before m365 login. Reproduce the reported certificateFile path and verify that m365 login succeeds without attempting to decode the path itself.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
authentication, cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.