共用方式為


設定Azure 應用程式以取得 SharePoint 存取權

在 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 存取。

  1. 開啟 Azure 入口網站

  2. Azure 服務下方,選取應用程式註冊

  3. 選取新增註冊

  4. 輸入應用程式的名稱

  5. 支援的帳戶類型下方,選取僅在此組織目錄中的帳戶

    注意

    目前不支援其他帳戶類型。

  6. 選取註冊以建立應用程式註冊

  7. 記下應用程式 (用戶端) 識別碼目錄 (租用戶) 識別碼

    1. 在導覽清單中,選取概觀
    2. Essentials 下方,複製應用程式 (用戶端) 識別碼目錄 (租用戶) 識別碼值以便在下一區段中使用。
  8. 在導覽清單中,選取管理>API 權限

  9. 已設定的權限下方,選取新增權限以開啟要求 API 權限面板。

    1. 選取 SharePoint
    2. 應用程式需要什麼類型的權限?下方,選取應用程式權限
    3. 選取權限下方,選取 Sites.FullControl.All
    4. 選取新增權限以建立 SharePoint 權限。
    5. 選取<tenant name>

伺服器設定先決條件

  1. 下載組件 "Microsoft.Identity.Client" 4.11.0 版的 NuGet 套件。

    1. 開啟https://www.nuget.org/packages/Microsoft.Identity.Client/4.11.0#readme-body-tab
    2. 關於底下,選取下載套件
  2. 將下載的套件從 "microsoft.identity.client.4.11.0.nupkg" 重新命名為 microsoft.identity.client.4.11.0.zip

  3. microsoft.identity.client.4.11.0.zip 執行解壓縮。

  4. 在解壓縮的目錄中,開啟 lib/net45 資料夾,然後尋找要在後面步驟中使用的檔案 “Microsoft.Identify.Client.dll” 和 “Microsoft.Identify.Client.xml”。

  5. 在 Dynamics 365 Customer Engagement (on-premises) Web 應用程式伺服器角色執行所在的 Windows Server 上,開啟 Internet Information Services 管理員

    1. 從 Windows 工作列開始功能表中開啟執行提示。
    2. 輸入 inetmgr,然後按 Enter。
  6. 展開連線窗格中的網站區段。

  7. 以滑鼠右鍵按一下 Microsoft Dynamics CRM 網站、選取探索,然後開啟 CRMWeb 資料夾。

  8. 開啟 bin 資料夾。

  9. 從解壓縮的 NuGet 套件目錄複製 "Microsoft.Identity.Client.dll" 和 "Microsoft.Identity.Client.xml" 這兩個檔案,然後在 bin 資料夾中貼上。

在 Dynamics 365 Customer Engagement 組織資料庫的 PartnerApplicationBase 資料表中建立 Azure 應用程式記錄

  1. 開啟 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
  1. 在指令碼中,將 @byoaAppId@tenantId 變數更新為您稍早本文建立具有 SharePoint 權限的 Azure 應用程式一節中從 Microsoft Azure 入口網站複製的應用程式識別碼租用戶識別碼值。

  2. 確認資料庫,然後執行指令碼。

  3. 執行選取查詢 SELECT * FROM [PartnerApplicationBase] 並驗證 PartnerApplicationIdTenantId 欄位以進行確認。

上傳 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 應用程式憑證

  1. 開啟網頁瀏覽器,然後前往 Azure 入口網站以取得第一節中建立的 Azure AD 應用程式。

  2. 展開管理,然後選取憑證和密碼

  3. 上傳建立的憑證檔案。

    1. 憑證區段下方,選取上傳憑證

    2. 使用上傳憑證來選取透過 PowerShell 指令碼建立的憑證檔案。

    3. 新增描述,然後選取新增

新建立的憑證會顯示在憑證清單中。