Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug report: o365 login using a certficate not working and how to pass the TenantId and AppClientid? #1532

Closed
ashokswain27 opened this issue Apr 27, 2020 · 11 comments

Comments

@ashokswain27
Copy link

ashokswain27 commented Apr 27, 2020

Trying to connect the o365 using a certificate.
https://pnp.github.io/office365-cli/user-guide/connecting-office-365/#log-in-using-a-certificate

Followed the below steps:
a) Create a self signed certificate and Personal Information Exchange (.pfx) file
b) Created an Azure AD App, Uploaded the same certficate(.cer file)
C) Granted the "SharePoint API permission"
d) Created the two variables OFFICE365CLI_AADAPPID and OFFICE365CLI_TENANT variables
I have verified the certificate key is available in the Azure AD app.

When executing the below command, got the below error. How to pass the tenantid and the clientid to this command?

AADSTS700027: Client assertion contains an invalid signature. [Reason - The key was not found., Thumbprint of key used by client: '', Please visit 'https://developer.microsoft.com/en-us/graph/graph-explorer' and
query for 'https://graph.microsoft.com/beta/applications/' to see configured keys]

o365 login --authType certificate --certificateFile ".\protected.pfx" --thumbprint ""

Expected result

O365 login should work with a certificate as per documentation.

Actual result

AADSTS700027: Client assertion contains an invalid signature. [Reason - The key was not found., Thumbprint of key used by client: '', Please visit 'https://developer.microsoft.com/en-us/graph/graph-explorer' and
query for 'https://graph.microsoft.com/beta/applications/' to see configured keys]

Environment

o365 version: 2.9.0

@ashokswain27 ashokswain27 changed the title Bug report: o365 login using a crtficate not working and how to pass the TenantId and AppClientid? Bug report: o365 login using a certficate not working and how to pass the TenantId and AppClientid? Apr 27, 2020
@waldekmastykarz
Copy link
Member

Is your certificated password-protected? If so, are you also specifying the password using the --password option?

@VelinGeorgiev
Copy link
Contributor

VelinGeorgiev commented Apr 28, 2020

@ashokswain27 , have you specified the thumbprint. By looking at the issue description it seems like you are passing an empty thumbprint which will fail the login.

You can find your thumbprint in the Azure AD app going on certificates and secrets
image

@ashokswain27
Copy link
Author

Yes, I have specified the thumbprint. Certificate is password-protected.

@ashokswain27
Copy link
Author

How do I pass the OFFICE365CLI_AADAPPID and OFFICE365CLI_TENANT variables into the command?
I am assuming the PowerShell command is ot reading the local variables while executing the below command
o365 login --authType certificate --certificateFile ".\protected.pfx" --thumbprint ""

@waldekmastykarz
Copy link
Member

These are environment variables that should be set on your machine and which will then be picked up by the CLI.

@waldekmastykarz
Copy link
Member

@ashokswain27 are you also specifying the certificate password?

@ashokswain27
Copy link
Author

Got it working now by specifying environment variables on my local dev machine. Is there any generic way to pass these variable explicitly in CI/CD pipeline in yml ? Otherwise, I have to set it up in the Azure VM under which the CI/CD pipeline is running.

@waldekmastykarz
Copy link
Member

If you execute CLI in bash you can do it like ENV1=value1 ENV2=value2 o365 command. Not sure if you can inline it the same way in PowerShell.

@ashokswain27
Copy link
Author

Awesome! in bash command : it is working fine. Thank you!

@VelinGeorgiev
Copy link
Contributor

Thank you @ashokswain27 ! Please let us know if you have any questions.

Great collaboration on this one. Thank you @waldekmastykarz !

@ashokswain27
Copy link
Author

No, I am good. Closing the issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants