Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Feature: Add support for Graph Cmdlets with Cert Thumbprint Authentication #2515

Merged
merged 2 commits into from
Mar 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Commands/Base/SPOnlineConnectionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,13 @@ private static SPOnlineConnection InitiateAzureAdAppOnlyConnectionWithCert(Uri u
var spoConnection = new SPOnlineConnection(context, connectionType, minimalHealthScore, retryCount, retryWait, null,
url.ToString(), tenantAdminUrl, PnPPSVersionTag, host, disableTelemetry, InitializationType.AADAppOnly);
spoConnection.ConnectionMethod = ConnectionMethod.AzureADAppOnly;

//Adding code to add a graph token when connecting with the certifcate thumbprint method
Microsoft.IdentityModel.Clients.ActiveDirectory.ClientAssertionCertificate cac = new Microsoft.IdentityModel.Clients.ActiveDirectory.ClientAssertionCertificate(clientId, certificate);
Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext authContext = new Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext($"https://login.microsoftonline.com/{tenant}");
Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationResult result = authContext.AcquireTokenAsync("https://graph.microsoft.com", cac).GetAwaiter().GetResult();
spoConnection.AccessToken = result.AccessToken;

if (certificateFromFile)
{
spoConnection.CertFile = certificate;
Expand Down