Deli z drugimi prek


Konfiguriranje aplikacije Azure za dostop do storitve SharePoint

opomba,

Novo in izboljšano Power Platform skrbniško središče je zdaj v javnem predogledu! Novo skrbniško središče smo zasnovali tako, da je enostavnejše za uporabo, z navigacijo, usmerjeno v opravila, ki vam pomaga hitreje doseči določene rezultate. Objavili bomo novo in posodobljeno dokumentacijo, ko bo novo Power Platform skrbniško središče prešlo v splošno dostopnost.

Uporaba tabele SharePoint Dokumenti v okolju Dynamics 365 zunaj mreže dokumentov v aplikaciji, ki temelji na modelu, zahteva aplikacijo Azure za odobritev dostopa. Primeri tega dostopa vključujejo uporabo znotraj Power Automate ali z Dataverse klici API. Nastavitev za odobritev dostopa uporablja Power Platform Upravljane identitete z Azure.

Od marca 2025 je trenutni dostop odstranjen zaradi izboljšanja zaščite sistema. Če želite zagotoviti stalen dostop, sledite tem korakom, da ustvarite aplikacijo Azure s potrebnimi SharePoint dovoljenji, nastavite upravljane identitete v Dataverse in konfigurirate zvezne poverilnice.

Ustvarite aplikacijo Azure z SharePoint dovoljenji

Ustvarite registracijo aplikacije z dovoljenjem API za SharePoint. Izvedite več o registraciji aplikacije in SharePoint dostopu v Azure Quickstart Register App in SharePoint dostopu prek Azure AD App-Only.

  1. Odprite portal Azure.

  2. V razdelku Storitve Azure izberite Registracije aplikacij.

  3. Izberite Nova registracija.

  4. Vnesite Ime za aplikacijo.

  5. Pod Podprte vrste računov izberite Samo računi v tem organizacijskem imeniku.

    opomba,

    Druge vrste trenutno niso podprte.

  6. Izberite Registracija , da ustvarite Registracijo aplikacije.

  7. Upoštevajte ID aplikacije (odjemalec) in ID imenika (najemnik):

    1. Na navigacijskem seznamu izberite Pregled.

    2. Pod Essentials kopirajte vrednosti Application (client) ID in Directory (tenant) ID za uporabo v naslednjem razdelku.

  8. Na navigacijskem seznamu izberite Upravljanje>dovoljenj API.

  9. V razdelku Konfigurirana dovoljenja izberite Dodaj dovoljenje da odprete ploščo Zahtevaj dovoljenja API .

    1. Izberite SharePoint.

    2. Pod Kakšno vrsto dovoljenj zahteva vaša aplikacija? izberite Dovoljenja za aplikacijo.

    3. V razdelku Izberite dovoljenja izberite Sites.FullControl.All.

    4. Izberite Dodaj dovoljenja da ustvarite SharePoint dovoljenje.

    5. Izberite Podeli skrbniško soglasje za <tenant name>.

Ustvari upravljane identitete v Dataverse

Ustvari upravljane zapise identitete v Dataverse. Več o upravljanih identitetah v Nastavitvi Dataverse Upravljanih identitetah.

Dodajte zapis v tabelo z upravljanimi identitetami

V tabelo managedidentities vstavite vrstico z vrednostmi iz naslednje tabele.

Polje tabele Vrednost
applicationid Uporabite vrednost ID aplikacije (odjemalca) iz prvega razdelka
tenantid Uporabite vrednost ID imenika (najemnika) iz prvega razdelka
managedidentityid Ustvari nov GUID
credentialsource 2
subjectscope 1

Primer uporabe POST:

  • Zahteva: https://contoso.crm.dynamics.com/api/data/v9.0/managedidentities

  • Telo:

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

Dodajte zapis v SharePoint tabelo upravljanih identitet

V tabelo sharepointmanagedidentity vstavite vrstico z vrednostmi iz naslednje tabele.

Polje tabele Vrednost
sharepointmanagedidentityid Ustvari nov GUID
uniquename "msft_ppmiforsharepointauth"
name "Upravljana identiteta za SharePoint Auth"
ManagedIdentity@odata.bind /managedidentities(<managedidentityid>) zamenjava <managedidentityid> z vrednostjo iz prejšnjega razdelka

Primer uporabe POST:

  • Zahteva: https://contoso.crm.dynamics.com/api/data/v9.0/sharepointmanagedidentities

  • Telo:

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

Ustvari zvezno poverilnico

Ustvarite zvezno poverilnico za registracijo aplikacije. Izvedite več o poverilnicah zvezne identitete v Konfigurirajte aplikacijo za poverilnice zvezne identitete.

opomba,

Poverilnice zvezne identitete prek Power Platform upravljane identitete so splošno na voljo in v celoti podprte za SharePoint integracijo dokumentov. Upravljana identiteta Power Platform se uporablja za številne scenarije, vendar niso vsi na splošno na voljo. Vendar je ta primer v celoti podprt.

  1. Odprite portal Azure.

  2. Izberite Microsoft Entra ID.

  3. Na navigacijskem seznamu izberite Upravljanje>Registracije aplikacij.

  4. Na seznamu aplikacij izberite registracijsko ime aplikacije, ustvarjeno v prejšnjem razdelku.

  5. Na navigacijskem seznamu izberite Manage>Certificates & skrivnosti.

  6. Izberite zavihek Zvezne poverilnice .

  7. Izberite Dodaj poverilnico.

  8. V polju Scenarij zveznih poverilnic izberite Drugi izdajatelj.

  9. V polje Izdajatelj vnesite URL izdajatelja:

    • Oblika vrednosti: https://login.microsoftonline.com/<tenantId>/v2.0
    • Zamenjajte <tenantId> z vrednostjo ID imenika (najemnika) GUID iz prejšnjega razdelka.
  10. V polje Vrednost vnesite identifikator subjekta:

    • Oblika vrednosti: /eid1/c/pub/t/<base64-encoded-tenantId>/a/<base64-encoded-appid>/Env/<orgid>/sharepointmanagedidentity/<sharepointmanagedidentityid>
    • Zamenjajte <base64-encoded-tenantId> z kodiranim ID-jem najemnika na podlagi 64.
    • Zamenjajte <base64-encoded-appid> z ID-jem odjemalca aplikacije s kodiranjem base64.
    • Zamenjajte <orgid> z ID-jem organizacije.
    • Zamenjajte <sharepointmanagedidentityid> z GUID-jem, ustvarjenim prej z zapisom sharepointmanagedidentities.

    [OPOMBA!] Uporabite skript v Generiraj identifikator subjekta , da ustvarite vrednost identifikatorja subjekta z vrednostmi, kodiranimi base64.

  11. Izberite Dodaj , da ustvarite poverilnico.

Če sledite tem korakom, konfigurirate aplikacijo Azure s potrebnimi SharePoint dovoljenji, nastavite upravljane identitete v Dataverse in konfigurirate zvezne poverilnice.

Ustvarite identifikator predmeta

Ta skript ustvari vrednost identifikatorja subjekta na podlagi vrednosti, navedenih v JavaScriptu.

  1. Odprite aplikacijo Dynamics 365 v brskalniku.

  2. Odprite orodja brskalnika na konzoli.

  3. Kopirajte naslednji JavaScript in nastavite vrednost za spremenljivko 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. Prilepite v konzolo za izvedbo.

  5. Kopirajte identifikator predmeta in ga prilepite v polje VrednostDodaj poverilnico.