在 Dynamics 365 Customer Engagement (on-premises) 應用程式的文件網格之外的 Dynamics 365 組織中使用 SharePoint 文件實體,需要 Azure 應用程式授與存取權。 此存取權的範例包括可在 Dynamics 365 Customer Engagement API 呼叫中使用。 此設定會將 Power Platform 受控識別與 Azure 搭配用來授與存取權。
重要
從 2025 年 3 月開始,將會移除目前的存取權以增強系統保護。 為確保繼續存取,請依照下列步驟建立具有必要 SharePoint 權限的 Azure 應用程式、在 Dynamics 365 Customer Engagement (on-premises) 組織中設定受控識別,並設定同盟認證。
建立具有 SharePoint 權限的 Azure 應用程式
建立具有 SharePoint API 權限的應用程式註冊。 在 Azure 快速入門註冊和透過 Azure AD 應用程式專用模式取得 SharePoint 存取權中深入了解如何註冊應用程式和 SharePoint 存取。
開啟 Azure 入口網站。
在 Azure 服務下方,選取應用程式註冊。
選取新增註冊。
輸入應用程式的名稱。
在支援的帳戶類型下方,選取僅在此組織目錄中的帳戶。
注意
目前不支援其他帳戶類型。
選取註冊以建立應用程式註冊。
記下應用程式 (用戶端) 識別碼和目錄 (租用戶) 識別碼。
- 在導覽清單中,選取概觀。
- 在 Essentials 下方,複製應用程式 (用戶端) 識別碼和目錄 (租用戶) 識別碼值以便在下一區段中使用。
在導覽清單中,選取管理>API 權限。
在已設定的權限下方,選取新增權限以開啟要求 API 權限面板。
- 選取 SharePoint。
- 在應用程式需要什麼類型的權限?下方,選取應用程式權限。
- 在選取權限下方,選取 Sites.FullControl.All。
- 選取新增權限以建立 SharePoint 權限。
- 為 選取
<tenant name>
。
伺服器設定先決條件
下載組件 "Microsoft.Identity.Client" 4.11.0 版的 NuGet 套件。
將下載的套件從 "microsoft.identity.client.4.11.0.nupkg" 重新命名為 microsoft.identity.client.4.11.0.zip,
對 microsoft.identity.client.4.11.0.zip 執行解壓縮。
在解壓縮的目錄中,開啟 lib/net45 資料夾,然後尋找要在後面步驟中使用的檔案 “Microsoft.Identify.Client.dll” 和 “Microsoft.Identify.Client.xml”。
在 Dynamics 365 Customer Engagement (on-premises) Web 應用程式伺服器角色執行所在的 Windows Server 上,開啟 Internet Information Services 管理員。
- 從 Windows 工作列開始功能表中開啟執行提示。
- 輸入 inetmgr,然後按 Enter。
展開連線窗格中的網站區段。
以滑鼠右鍵按一下 Microsoft Dynamics CRM 網站、選取探索,然後開啟 CRMWeb 資料夾。
開啟 bin 資料夾。
從解壓縮的 NuGet 套件目錄複製 "Microsoft.Identity.Client.dll" 和 "Microsoft.Identity.Client.xml" 這兩個檔案,然後在 bin 資料夾中貼上。
在 Dynamics 365 Customer Engagement 組織資料庫的 PartnerApplicationBase 資料表中建立 Azure 應用程式記錄
- 開啟 SQL Server 管理工作室,並在此 SQL 指令碼中複製。
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
在指令碼中,將 @byoaAppId 和 @tenantId 變數更新為您稍早本文建立具有 SharePoint 權限的 Azure 應用程式一節中從 Microsoft Azure 入口網站複製的應用程式識別碼和租用戶識別碼值。
確認資料庫,然後執行指令碼。
執行選取查詢
SELECT * FROM [PartnerApplicationBase]
並驗證 PartnerApplicationId 和 TenantId 欄位以進行確認。
上傳 Azure 應用程式憑證中的憑證
使用此指令碼擷取現有的 Dynamics 365 Customer Engagement (on-premises) 憑證。
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
}
}
將現有憑證上傳至 Azure 應用程式憑證
開啟網頁瀏覽器,然後前往 Azure 入口網站以取得第一節中建立的 Azure AD 應用程式。
展開管理,然後選取憑證和密碼。
上傳建立的憑證檔案。
在憑證區段下方,選取上傳憑證。
使用上傳憑證來選取透過 PowerShell 指令碼建立的憑證檔案。
新增描述,然後選取新增。
新建立的憑證會顯示在憑證清單中。