次の方法で共有


SharePoint へのアクセスに使用する Azure アプリを構成する

注意

新機能と改善された Power Platform 管理センター は、現在パブリック プレビュー段階にあります。 新しい管理センターは、特定の結果をより迅速に達成するのに役立つタスク指向のナビゲーションで使いやすくなるように設計されています。 新しい Power Platform 管理センターが 一般提供 に移行する、新しいドキュメントと更新されたドキュメントを公開します。

Dynamics 365 環境の SharePoint Documents テーブルを、モデル駆動型アプリのドキュメント グリッド以外で使用するには、アクセスを許可する Azure アプリケーションが必要です。 このアクセスの場合は、Power Automate 内または Dataverse の API 呼び出しでの使用が含まれます。 このセットアップでは、Power Platform のマネージド ID と Azure を使用してアクセスを許可します。

2025 年 3 月以降、システム保護を強化するため、現在のアクセスは削除されます。 継続的にアクセスできるようにするには、以下の手順に従って、必要な SharePoint 権限を持つ Azure アプリケーションを作成し、Dataverse でマネージド ID を設定し、連携された認証情報を構成します。

SharePoint 権限を持つ Azure アプリケーションの作成

SharePoint への API 権限を持つアプリの登録を作成します。 アプリの登録と SharePoint アクセスの詳細については、Azure Quickstart Register AppAzure AD App のみを介した SharePoint へのアクセス を参照してください。

  1. Azure Portal を開きます。

  2. Azure サービスで、アプリの登録 を選択します。

  3. 新規登録を選択します。

  4. アプリケーションの名前を入力します。

  5. サポートされるアカウントの種類で、この組織ディレクトリのアカウントのみを選択します。

    ヒント

    その他のタイプは現在サポートされていません。

  6. 登録を選択して、アプリの登録を作成します。

  7. アプリケーション (クライアント) IDディレクトリ (テナント) IDをメモします:

    1. ナビゲーション リストで、概要を選択します。

    2. Essentials で、次のセクションで使用する アプリケーション (クライアント) IDディレクトリ (テナント) ID の値をコピーします。

  8. ナビゲーション リストで、監視>API アクセス許可 を選択します。

  9. 構成されたアクセス許可アクセス許可の追加 を選択して API アクセス許可の要求 パネルを開きます。

    1. SharePoint を選択します。

    2. アプリケーションにどのような種類のアクセス許可が必要ですか?で、 アプリケーションのアクセス許可を選択します。

    3. アクセス許可の選択Sites.FullControl.All を選択します。

    4. アクセス許可の追加を選択して、SharePoint のアクセス許可を作成します。

    5. <tenant name> に対して管理者の同意の付与するを選択します。

Dataverse でマネージド ID を作成する

Dataverse でマネージド ID を作成します。 マネージド ID の詳細については、 Dataverse のマネージド ID を設定するを参照してください。

マネージド ID テーブルにレコードを追加する

次の表の値を使用して managedidentities のテーブルに行を挿入します。

テーブル フィールド 価値
applicationid 最初のセクションのアプリケーション (クライアント) ID の値を使用します
tenantid 最初のセクションのディレクトリ (テナント) ID の値を使用します
managedidentityid 新しい GUID の作成
credentialsource 2
subjectscope 6

POST を使用した例:

  • リクエスト: https://contoso.crm.dynamics.com/api/data/v9.0/managedidentities

  • 本文:

    {
    "applicationid": "<appId>",
    "managedidentityid": "<newGuid>",
    "credentialsource": 2,
    "subjectscope": 1,
    "tenantid": "<tenantId>"
    }
    

SharePoint のマネージド ID テーブルにレコードを追加する

次の表の値を使用して sharepointmanagedidentity のテーブルに行を挿入します。

テーブル フィールド 価値
sharepointmanagedidentityid 新しい GUID の作成
uniquename "msft_ppmiforsharepointauth"
name "SharePoint 認証のマネージド ID"
ManagedIdentity@odata.bind /managedidentities(<managedidentityid>)<managedidentityid> に置き換えて、前のセクションの値を使用します

POST を使用した例:

  • リクエスト: https://contoso.crm.dynamics.com/api/data/v9.0/sharepointmanagedidentities

  • 本文:

    {
    "sharepointmanagedidentityid": "<newGuid>",
    "uniquename": "msft_ppmiforsharepointauth",
    "name": "Managed Identity For SharePoint Auth",
    "ManagedIdentityId@odata.bind": "/managedidentities(<managedIdentityId>)"
    }
    

フェデレーション資格情報の作成

アプリ登録用の連携する資格情報を作成します。 フェデレーション ID の資格情報の詳細については、フェデレーション ID の資格情報用にアプリケーションを構成するを参照してください。

注意

Power Platform マネージド ID を介したフェデレーション ID 資格情報が一般提供され、ドキュメント SharePoint 統合で完全にサポートされています。 Power Platform マネージド ID は多くのシナリオで使用されますが、すべてが一般に利用できるわけではありません。 ただし、このケースは完全にサポートされています。

  1. Azure Portal を開きます。

  2. Microsoft Entra ID を選択します。

  3. ナビゲーション リストで、管理>アプリの登録 を選択します。

  4. アプリケーションの一覧で、前のセクションで作成したアプリ登録名を選択します。

  5. ナビゲーション リストで、管理>証明書とシークレット を選択します

  6. 連携された資格情報タブを選択します。

  7. 資格情報の追加を選択します。

  8. 連携された資格情報のシナリオ フィールドで、その他の発行者を選択します。

  9. 発行者 フィールドで、発行者の URL を入力します。

    • 値の書式: https://login.microsoftonline.com/<tenantId>/v2.0
    • <tenantId> を前のセクションのディレクトリ (テナント) ID の GUID 値に置き換えます。
  10. フィールドに、サブジェクトの識別子を入力します:

    • 値の書式: /eid1/c/pub/t/<base64-encoded-tenantId>/a/<base64-encoded-appid>/Env/<orgid>/sharepointmanagedidentity/<sharepointmanagedidentityid>
    • <base64-encoded-tenantId> を base64 エンコードされたテナント ID に置き換えます。
    • <base64-encoded-appid> を base64 エンコードされたアプリのクライアント ID に置き換えてください。
    • <orgid> を組織の ID で置換します。
    • <sharepointmanagedidentityid> を、以前に sharepointmanagedidentities レコードで作成した GUID に置き換えます。

    [注意!] サブジェクト識別子の生成 のスクリプトを使用して、Base64 でエンコードされた値でサブジェクト識別子の値を生成します。

  11. 追加 を選択して資格情報を作成します。

以下の手順に従って、必要な SharePoint 権限で Azure アプリケーションを構成し、Dataverse でマネージド ID を設定して、連携認証情報を構成します。

サブジェクト識別子を生成する

このスクリプトは、JavaScript で指定された値に基づいてサブジェクト識別子の値を生成します。

  1. ブラウザーで、Dynamics 365 アプリケーションを開きます。

  2. コンソールのブラウザツールを開きます。

  3. 次の JavaScript をコピーし、変数 sharePointManagedIdentityId の値を設定します。

    // Replace with the id for SharePoint Managed Identity that was created attribute name: sharepointmanagedidentityid.
    // Refer to the following documentation for configuring an aad app for SharePoint access:
    //     https://learn.microsoft.com/en-us/power-platform/admin/configure-azure-app-with-sharepoint-access
    // For the SharePoint Managed Identity creation, refer to the following documentation:
    //     https://learn.microsoft.com/en-us/power-platform/admin/configure-azure-app-with-sharepoint-access#add-record-in-sharepoint-managed-identities-table
    const sharePointManagedIdentityId = "";
    
    const prefixForFICIssuer = "https://login.microsoftonline.com/";
    const suffixForFICIssuer = "/v2.0";
    const prefixForFICSubject = "/eid1/c/pub";
    const tenantIdentifierForFICSubject = "/t/";
    const appIdentifierForFICSubject = "/a/";
    const environmentIdentifierForFICSubject = "/Env/";
    const sharePointManagedIdentityIdentifierForFICSubject = "/sharepointmanagedidentity/";
    
    // This is the AAD App Id to be used for Power Platform Managed Identity: 58e835ab-2e39-46a9-b797-accce6633447
    const powerPlatformManagedIdentityAppId = "58e835ab-2e39-46a9-b797-accce6633447";
    
    /**
     * Represents a request for retrieving the current organization.
     * @param {number} accessType - The access type (0 for Default, 1 for Internet, 2 for Intranet).
     */
    var RetrieveCurrentOrganizationRequest = function (accessType) {
        this.AccessType = accessType;
    };
    
    /**
     * Gets metadata for the request.
     * @returns {Object} The metadata for the request.
     */
    RetrieveCurrentOrganizationRequest.prototype.getMetadata = function() {
        return {
            boundParameter: null,
            parameterTypes: {
                "AccessType": {
                    "typeName": "Microsoft.Dynamics.CRM.EndpointAccessType",
                    "structuralProperty": 3,  // Enum Type
                    "enumProperties": [
                        { "name": "Default", "value": 0 },
                        { "name": "Internet", "value": 1 },
                        { "name": "Intranet", "value": 2 }
                    ]
                }
            },
            operationType: 1, // This is a function
            operationName: "RetrieveCurrentOrganization"
        };
    };
    
    /**
     * Encodes a GUID to a Base64 URL-safe string.
     *
     * @param {string} guid - The GUID to encode.
     * @returns {string} The Base64 URL-safe encoded string.
     * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/btoa}
     */
    function encodeToBase64Url(guid) {
        const buffer = [];
        const regex = /.{1,2}/g;
    
        guid.split('-').forEach((number, index) => {
            const bytesInChar = number.match(regex);
            if (index < 3) bytesInChar.reverse();
            bytesInChar.forEach(byte => buffer.push(parseInt(byte, 16)));
        });
    
        const base64String = btoa(String.fromCharCode.apply(null, new Uint8Array(buffer)));
    
        // Make the Base64 string URL-safe by replacing '+' with '-' and '/' with '_'
        // Remove any trailing '=' characters
        return base64String.slice(0, 22).replace(/=+$/, '').replace(/\+/g, '-').replace(/\//g, '_');
    }
    
    /**
     * Construct the issuer URL using the tenant ID.
     * This is needed for the issuer url in FIC configuration.
     * @param {string} tenantId - The tenant ID.
     * @returns {string} The constructed issuer URL.
     * @example
     * // Example for output
     * // https://login.microsoftonline.com/your-tenant-id/v2.0
     */
    function constructIssuerUrlForFIC(tenantId) {
        return `${prefixForFICIssuer}${tenantId}${suffixForFICIssuer}`;
    }
    
    /**
     * Constructs the subject url using the encoded tenant ID, encoded app ID, environment ID, and SharePoint managed identity ID.
     * This is needed for the subject url in FIC configuration.
     * @param {string} encodedTenantId - The encoded tenant ID.
     * @param {string} encodedAppId - The encoded app ID.
     * @param {string} environmentId - The environment ID.
     * @param {string} sharePointManagedIdentityId - The SharePoint managed identity ID.
     * @returns {string} The constructed subject string.
     * @example
     * // Example output: /eid1/c/pub/t/<EncodedTenantId>/a/<EncodedDV1PAppId>/Env/<EnvironmentId>/sharepointmanagedidentity/<sharePointManagedIdentityId>
     */
    function constructSubjectUrlForFIC(encodedTenantId, encodedAppId, environmentId, sharePointManagedIdentityId) {
        return `${prefixForFICSubject}${tenantIdentifierForFICSubject}${encodedTenantId}${appIdentifierForFICSubject}${encodedAppId}${environmentIdentifierForFICSubject}${environmentId}${sharePointManagedIdentityIdentifierForFICSubject}${sharePointManagedIdentityId}`;
    }
    
    (async () => {
        try {
            // Check if sharePointManagedIdentityId is null or undefined
            if (!sharePointManagedIdentityId) {
                console.error("SharePoint Managed Identity ID is null or undefined. Please ensure that the SharePoint Managed Identity ID is set.");
                return;
            }
    
            const accessType = 0;
            const retrieveCurrentOrganizationRequest = new RetrieveCurrentOrganizationRequest(accessType);
    
            // Execute the request to retrieve the current organization details
            // https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/xrm-webapi/online/execute
            // https://learn.microsoft.com/en-us/power-apps/developer/data-platform/webapi/web-api-functions-actions-sample#section-4-unbound-function-retrievecurrentorganization
            const response = await Xrm.WebApi.online.execute(retrieveCurrentOrganizationRequest);
            const result = await response.json();
    
            if (result.Detail) {
                const { EnvironmentId: environmentId, TenantId: tenantId } = result.Detail;
    
                const encodedTenantId = encodeToBase64Url(tenantId);
                const encodedPowerPlatformManagedIdentityAppId = encodeToBase64Url(powerPlatformManagedIdentityAppId);
                const issuerUrlForFederatedCredentialConfig = constructIssuerUrlForFIC(tenantId);
                const subjectUrlForFederatedCredentialConfig = constructSubjectUrlForFIC(encodedTenantId, encodedPowerPlatformManagedIdentityAppId,
                     environmentId, sharePointManagedIdentityId);
    
                console.log(`SharePoint Managed Identity ID: ${sharePointManagedIdentityId},
                    Tenant ID: ${tenantId},
                    Encoded Tenant ID: ${encodedTenantId},
                    Power Platform Managed Identity App ID: ${powerPlatformManagedIdentityAppId},
                    Encoded App ID: ${encodedPowerPlatformManagedIdentityAppId},
                    Issuer URL for Federated Credential Configuration: ${issuerUrlForFederatedCredentialConfig},
                    Subject URL for Federated Credential Configuration: ${subjectUrlForFederatedCredentialConfig}`);
            } else {
                console.error("RetrieveCurrentOrganization response is missing detail.");
            }
        } catch (error) {
            console.error(`Error executing request: ${error.message}`);
        }
    })();
    
  4. コンソールにペーストして実行します。

  5. サブジェクト識別子をコピーして、資格情報の追加フィールドに貼り付けます。