Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Using the SharePoint Documents entity in a Dynamics 365 organization outside of the documents grid in a Dynamics 365 Customer Engagement (on-premises) app requires an Azure application to grant access. An example of this access includes use within Dynamics 365 Customer Engagement API calls. The setup uses the Power Platform Managed Identities with Azure to grant access.
Important
Starting in March 2025, the current access is removed to enhance system protection. To ensure continued access, follow these steps to create an Azure application with the necessary SharePoint permissions, set up managed identities in your Dynamics 365 Customer Engagement (on-premises) organization, and configure federated credentials.
Create an Azure application with SharePoint permissions
Create an app registration with API permission to SharePoint. Learn more about registering an app and SharePoint access in Azure Quickstart Register App and SharePoint access via Azure AD App-Only.
Open the Azure portal.
Under Azure services, select App registrations.
Select New registration.
Enter a Name for the application.
Under Supported account types, select Accounts in this organizational directory only.
Note
Other account types aren't currently supported.
Select Register to create the App registration.
Note the Application (client) ID and Directory (tenant) ID.
- In the navigation list, select Overview.
- Under Essentials, copy the Application (client) ID and Directory (tenant) ID values for use in the next section.
In the navigation list, select Manage > API permissions.
Under Configured permissions, select Add a permission to open the Request API permissions panel.
- Select SharePoint.
- Under What type of permissions does your application require?, select Application permissions.
- Under Select permissions, select Sites.FullControl.All.
- Select Add permissions to create the SharePoint permission.
- Select Grant admin consent for the
<tenant name>
.
Server setup prerequisites
Apply update from Service Update 1.36 for Microsoft Dynamics CRM (on-premises) 9.1 - Microsoft Support
Download the NuGet package for assembly "Microsoft.Identity.Client" version 4.11.0.
- Open https://www.nuget.org/packages/Microsoft.Identity.Client/4.11.0#readme-body-tab
- Under About, select Download package
Rename the downloaded package from "microsoft.identity.client.4.11.0.nupkg" to microsoft.identity.client.4.11.0.zip.
Run extract on microsoft.identity.client.4.11.0.zip.
Within the extracted directory, open the lib/net45 folder and find the files "Microsoft.Identify.Client.dll" and "Microsoft.Identify.Client.xml" to use in a later step.
On the Windows Server where the Dynamics 365 Customer Engagement (on-premises) web application server role is running, open Internet Information Services Manager.
- Open the Run prompt from the Windows task bar Start menu.
- Type inetmgr, and then press Enter.
Expand the Sites section in the Connections pane.
Right-click the Microsoft Dynamics CRM site, select Explore, and then open the CRMWeb folder.
Open the bin folder.
Copy the two files "Microsoft.Identity.Client.dll" and "Microsoft.Identity.Client.xml" from the extracted NuGet package directory, and then paste both into the bin folder.
Create Azure application record in PartnerApplicationBase table in Dynamics 365 Customer Engagement organization database
- Open SQL Server Management Studio and copy in this SQL script.
IF (SELECT COUNT(*)
FROM OrganizationBase WITH (NOLOCK)) <> 1
THROW 51000, 'Organization records does not equal 1', 1
DECLARE @organizationId UNIQUEIDENTIFIER = (SELECT OrganizationId
FROM OrganizationBase WITH (NOLOCK));
DECLARE @utcNow DATETIME = GetUtcDate();
DECLARE @principalId UNIQUEIDENTIFIER = '00000003-0000-0ff1-ce00-000000000000';
DECLARE @applicationName NVARCHAR(100) = 'Microsoft SharePoint Online';
DECLARE @byoaAppId UNIQUEIDENTIFIER = '<appId>';
--Customer need to provide the app id.
DECLARE @tenantId UNIQUEIDENTIFIER = '<tenantId';
BEGIN TRANSACTION InsertRows
INSERT INTO [dbo].[PartnerApplicationBase]
([PrincipalId]
,[StateCode]
,[Name]
,[UseAuthorizationServer]
,[PartnerApplicationId]
,[StatusCode]
,[ApplicationRole]
,[OrganizationId]
,[CreatedOn]
,[ModifiedOn]
,[TenantId])
VALUES
(@principalId
, 0
, @applicationName
, 1
, @byoaAppId
, 1
, 1
, @organizationId
, @utcNow
, @utcNow
, @tenantId)
COMMIT TRANSACTION InsertRows
In the script, update the @byoaAppId and @tenantId variables with the Application ID and Tenant ID values you copied earlier from the Microsoft Azure portal in the Create an Azure application with SharePoint permissions section of this article.
Verify the database and then execute the script.
Confirm by running the select query
SELECT * FROM [PartnerApplicationBase]
and verifying the PartnerApplicationId and TenantId fields.
Upload certificate in Azure app certificates
Fetch the existing Dynamics 365 Customer Engagement (on-premises) certificate using this script.
cd $PSScriptRoot
$OutputFilePath = $PSScriptRoot + "\certificates\existing_crmsharepoints2s.cer"
$RemoveSnapInWhenDone = $False
if (-not (Get-PSSnapin -Name Microsoft.Crm.PowerShell -ErrorAction SilentlyContinue)) {
Add-PSSnapin Microsoft.Crm.PowerShell
$RemoveSnapInWhenDone = $True
}
try {
# Ensure the directory exists
$directory = [System.IO.Path]::GetDirectoryName($OutputFilePath)
if (-not (Test-Path -Path $directory)) {
New-Item -ItemType Directory -Path $directory | Out-Null
}
# Fetch existing certificate using Get-CrmCertificate and filter by CertificateType
$existingCert = Get-CrmCertificate | Where-Object { $_.CertificateType -eq "S2STokenIssuer" }
if ($null -eq $existingCert) {
Write-Error "No certificate found with CertificateType 'S2STokenIssuer'."
return
}
# Store the certificate in the specified path
$certBytes = [Convert]::FromBase64String($existingCert.Data)
[System.IO.File]::WriteAllBytes($OutputFilePath, $certBytes)
Write-Output "Certificate saved to $OutputFilePath"
}
catch {
Write-Error "An error occurred: $_"
}
finally {
if ($RemoveSnapInWhenDone) {
Remove-PSSnapin Microsoft.Crm.PowerShell
}
}
If the PowerShell script returns "No certificate found with CertificateType 'S2STokenIssuer'.", then
Find the CRM server with the deployment tools role
Log on using a CRM deployment administrator
Replace @crmCertFile with the full path certificate file and run the PowerShell script as an administrator
add-pssnapin microsoft.crm.powershell $CrmCertificate = "@crmCertFile" Params = @{ CertificateType = S2STokenIssuer StoreName = My StoreLocation = LocalMachine StoreFindType = FindBySubjectDistinguishedName DataFile = $CrmCertificate } Set-CrmCertificate @Params
Upload the existing certificate to Azure application certificates
Open a web browser and go to the Azure portal for the Azure AD app that was created in the first section.
Expand Manage, and then select Certificates & Secrets.
Upload the created certificate file.
Under the Certificates section, select Upload certificate.
Use Upload a certificate to select the certificate file that was created from the PowerShell script.
Add the Description, and then select Add.
The newly created certificate is shown in the Certificates list.