SOLVED: Connect-ExchangeOnline: Could not use the certificate for signing. See inner exception for details. Possible cause: this may be a known issue with apps build against .NET Desktop 4.6 or lower.
When you try and connect to Exchange Online using a service principal and client certificate such as this
Connect-ExchangeOnline -AppId "identifier" -CertificateThumbprint "thumbprint" -Organization "yourdomain.onmicrosoft.com";
You may see the following error
Could not use the certificate for signing. See inner exception for details. Possible cause: this may be a known issue with apps build against .NET Desktop 4.6 or lower. Either target a higher version of .NET desktop - 4.6.1 and above, or use a different certificate type (non-CNG) or sign your own assertion as described at https://aka.ms/msal-net-signed-assertion.
Problem: The certificate you're using is too secure for the Exchange Online PowerShell cmdlets.
If you read the Microsoft Guidance here you'll see their examples use older encryption which does work correctly.
This seems to be an issue with the Exchange Online PowerShell (even at version 3.4.0) perhaps the libraries are compiled using an old version of .NET?
Solution:
It's not a great solution you'll need to access the Microsoft Authentication libraries (MSAL)
https://www.nuget.org/packages/Microsoft.Identity.Client/
You can then authenticate with the Microsoft authentication servers and get the token to allow access to Exchange that you need yourself. This token can then be passed to the Connect-ExchangeOnline cmdlet.
# Set the variables
$msalPath = "D:\CENTRELSolutions\3rdParty\Microsoft\Microsoft Authentication Library (MSAL)";
$thumbprint = "yourthumbprint";
$applicationIdentifier = "appidentifier";
$organization = "yourorganization.onmicrosoft.com";
$environment = [Microsoft.Identity.Client.AzureCloudInstance]::AzurePublic;
# Authenticate
Add-Type -Path "$msalPath\Microsoft.IdentityModel.Abstractions.dll";
Add-Type -Path "$msalPath\Microsoft.Identity.Client.dll";
$certificate = Get-ChildItem -Path "Cert:\CurrentUser\My\$thumbprint";
[string[]] $Scopes = "https://outlook.office365.com/.default";
[Microsoft.Identity.Client.IConfidentialClientApplication] $application =
[Microsoft.Identity.Client.ConfidentialClientApplicationBuilder]::Create($applicationIdentifier).WithCertificate($certificate).WithAuthority($environment, $tenantIdentifier).Build();
$result = $application.AcquireTokenForClient($scopes).ExecuteAsync().Result;
# You can now connect to Exchange Online
Connect-ExchangeOnline -AccessToken $result.AccessToken -Organization $organization;
While you're here why not check out our Exchange audit and documentation tool?
Comments
Post a Comment