Outils pour utilisateurs

Outils du site


reseau:cloud:azure:configurerapppoursharepoint

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
reseau:cloud:azure:configurerapppoursharepoint [2026/04/05 22:51] – [Installer Microsoft.Graph de Powershell] techer.charles_educ-valadon-limoges.frreseau:cloud:azure:configurerapppoursharepoint [2026/04/05 23:35] (Version actuelle) – [Créer un dossier dans le site SharePoint] techer.charles_educ-valadon-limoges.fr
Ligne 129: Ligne 129:
  
      
- 
   * Export du certificat PUBLIC à importer dans Entra ID   * Export du certificat PUBLIC à importer dans Entra ID
  
Ligne 138: Ligne 137:
 </code> </code>
  
-    * importer le certificat dans l'application+  * importer le certificat dans l'application à partir du portail Azure 
 + 
 +  * Test avec PowerShell (certificat local)
  
 <code> <code>
-Add-MgApplicationKey  +Connect-MgGraph   
-     -ApplicationId $app.Id  +   -TenantId "<TENANT_ID>"   
-     -KeyCredentialFile "application.cer+   -ClientId "<APP_ID>`   
-</code>+   -CertificateThumbprint "<THUMBPRINT>
  
-===================== +=> Résultat attendu 
- +Plain TextWelcome To Microsoft Graph! 
-  * script Powershell pour se conncter t etest la création d'un dossier +</code>
  
-<WRAP center round important> +  * Puis :
-Il est important de se connecter en tant qu'application et non en tant qu'utilisateur. +
-</WRAP>+
  
 <code> <code>
-############################################################ +Get-MgContext
-# CONFIGURATION pour l'accès avec l'application enregistrée +
-############################################################+
  
-$TenantId     "Tenant_educ-valadon# +=> on doit voir :
-$AppId        = "APP_ID_DE_TON_APPLICATION"+
  
-$Thumbprint = "EMPREINTE_DU_CERTIFICAT"+ClientId               : <id client> 
 +TenantId               : <ID tenant> 
 +Scopes                 : {Sites.Selected} 
 +AuthType               : AppOnly 
 +TokenCredentialType    : ClientCertificate 
 +CertificateThumbprint  : <empreinte> 
 +</code>
  
-$SitePath      "/sites/Signaturesnumriques" +==== Donner accès à l'application sur le site Sharepoint====
-$NewFolderName "Test-SitesSelected-Cert-OK"+
  
 +   * l'administrateur doit donner l'accès au site voulu
  
 +<code>
 +# deconnexion
 +Disconnect-MgGraph
  
-$SitePath = "/sites/Signaturesnumriques" +# Connexion admin 
-$NewFolderName = "Test-SitesSelected-OK"+Connect-MgGraph -Scopes "Sites.FullControl.All"
  
-############################################################ +Récupérer le site 
-# ÉTAPE 1 – OBTENIR UN TOKEN D’APPLICATION (CLIENT CREDENTIALS) +$site = Get-MgSite -SiteId "mondomaine.sharepoint.com:/sites/MonSite"
-############################################################+
  
-Write-Host "Authentification par certificat…"+# Donner accès controle total à l'application (fullcontrol / read / write) 
 +New-MgSitePermission ` 
 +  -SiteId $site.Id ` 
 +  -Roles "fullcontrol"
 +  -GrantedToIdentities @{ 
 +      Application = @{ 
 +          Id = "ID application" 
 +          DisplayName = "application" 
 +      } 
 +  } 
 +</code> 
 +  
 +  * Se reconnecter en AppOnly :
  
-$cert = Get-Item "Cert:\LocalMachine\My\$Thumbprint"+<code> 
 +Connect-MgGraph `   
 +    -TenantId "1ae69c2d-61b2-4de4-84c7-2a4dd0de7330" `   
 +    -ClientId "5c82fc87-6e0c-413f-ac12-6d784af9a249" `   
 +    -CertificateThumbprint "97F825CFD5C0371D28E1D691140A084B9C2C4386" 
 +</code>
  
-$assertion = [Microsoft.Identity.Client.ConfidentialClientApplicationBuilder]::Create($AppId). +  * Puis Tester l’accès au site précis:
-    WithTenantId($TenantId). +
-    WithCertificate($cert). +
-    Build()+
  
-$tokenResult = $assertion.AcquireTokenForClient(@("https://graph.microsoft.com/.default")). +<code> 
-    ExecuteAsync().GetAwaiter().GetResult()+Get-MgSite -SiteId "mondomaine.sharepoint.com:/sites/MonSite
 +</code>
  
-$Headers = @{ 
-    Authorization = "Bearer $($tokenResult.AccessToken)" 
-} 
  
-Write-Host "Token d'application obtenu via certificat"+==== Créer un dossier dans le site SharePoint ====
  
 +  * Identifier le site SharePoint en itilisant le chemin direct :
  
-############################################################ +<code> 
-# ÉTAPE 2 – RÉCUPÉRER LE SITE SHAREPOINT PAR SON URL +$site = Get-MgSite -SiteId "mondomaine.sharepoint.com:/sites/MonSite" 
-############################################################+$site.Id
  
-Write-Host "Récupération du site SharePoint..."+=> Afficher le GUID du site du type : 
 +xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx 
 +</code>
  
-$site = Invoke-RestMethod ` +   * Récupérer le drive du site (Documents) chaque site a une document library principale.
-    -Method GET ` +
-    -Uri "https://graph.microsoft.com/v1.0/sites/educvaladonlimogesfr.sharepoint.com:$SitePath"+
-    -Headers $Headers+
  
-$SiteId = $site.id +<code> 
- +$drive Get-MgSiteDrive -SiteId $site.Id 
-Write-Host "Site trouvé : $($site.displayName)" +$drive.Id
-Write-Host "SiteId : $SiteId" +
- +
-############################################################ +
-# ÉTAPE 3 – ATTRIBUER LA PERMISSION WRITE +
-############################################################ +
- +
-Write-Host "Attribution de la permission WRITE à l'application..." +
- +
-$permissionBody @{ +
-    roles = @("write"+
-    grantedToIdentities = @( +
-        @{ +
-            application = @{ +
-                id = $AppId +
-            } +
-        } +
-    ) +
-} | ConvertTo-Json -Depth 5 +
- +
-Invoke-RestMethod ` +
-    -Method POST ` +
-    -Uri "https://graph.microsoft.com/v1.0/sites/$SiteId/permissions"+
-    -Headers $Headers ` +
-    -Body $permissionBody ` +
-    -ContentType "application/json" +
- +
-Write-Host "Permission Sites.Selected (write) appliquée" +
- +
-############################################################ +
-# ÉTAPE 4 – TEST : CRÉATION D’UN DOSSIER DANS SHAREPOINT +
-############################################################ +
- +
-Write-Host "Test : création d’un dossier SharePoint..." +
- +
-$folderBody = @{ +
-    name = $NewFolderName +
-    folder = @{} +
-} | ConvertTo-Json +
- +
-Invoke-RestMethod ` +
-    -Method POST ` +
-    -Uri "https://graph.microsoft.com/v1.0/sites/$SiteId/drive/root/children"+
-    -Headers $Headers ` +
-    -Body $folderBody ` +
-    -ContentType "application/json" +
- +
-Write-Host "SUCCÈS : le dossier '$NewFolderName' a été créé dans SharePoint"+
  
 +=> Affiche un DriveId
 +Type : documentLibrary
 </code> </code>
  
-  * Donner accès à l'application sur le site+  * Créer un dossier À LA RACINE (test simple).
  
 <code> <code>
-Grant-MgSitePermission -SiteId $site.Id -Roles "write" -GrantedToIdentities @{ application = @{ id = "APP_ID}+New-MgDriveRootChild ` 
 +  -DriveId $drive.Id 
 +  -AdditionalProperties @{ 
 +      "name= "Test-Dossier" 
 +      "folder" = @{
 +      "@microsoft.graph.conflictBehavior" = "rename" 
 +  }
  
-Grant-MgSitePermission ` 
-    -SiteId $site.Id ` 
-    -Roles "write" ` 
-    -GrantedToIdentities @{ application = @{ id = "APP_ID" } } 
  
 +=> Résultat attendu
 +Id   : 01ABCDEF....
 +Name : Test-Dossier
 +=> Dossier créé avec succès à vérifier dans SharePoint
 </code> </code>
  
-  * Tester l’accès avec Microsoft Graph  (avec client secret)+  * lister les dossier à la racine
  
-Variables requises 
 <code> <code>
-$tenantId     "<TON_TENANT_ID>" +$items Get-MgDriveRootChild -DriveId $drive.Id
-$clientId     = "<APP_ID>" +
-$clientSecret = "<CLIENT_SECRET>" +
-$siteId       = $site.Id+
 </code> </code>
  
-  * Obtenir un token avec l’application+  * Récupérer le dossier General
  
 <code> <code>
-$tokenBody @{ +$parent $items | Where-Object { $_.Name -eq "General" } 
-    client_id     $clientId +$parent.Id 
-    scope         = "https://graph.microsoft.com/.default+</code>
-    client_secret = $clientSecret +
-    grant_type    = "client_credentials" +
-}+
  
-  *  Créer un dossier dans le site SharePoint+  * création du sous-dossier
  
 <code> <code>
-$headers = @{ Authorization = "Bearer $token" } +New-MgDriveItemChild ` 
-$body = '"name""DossierTestCopilot""folder"{} }' +  -DriveId $drive.Id ` 
- +  -DriveItemId $parent.Id ` 
-Invoke-RestMethod ` +  -AdditionalProperties @{ 
-    -Uri "https://graph.microsoft.com/v1.0/sites/$siteId/drive/root/children+      "name" "Test-SousDossier" 
-    -Headers $headers ` +      "folder" = @{} 
-    -Method POST ` +      "@microsoft.graph.conflictBehavior"rename" 
-    -Body $body ` +  }
-    -ContentType "application/json"+
 </code> </code>
- 
 ==== Installer le module module PnP.PowerShell ==== ==== Installer le module module PnP.PowerShell ====
 PnP.PowerShell supporte : PnP.PowerShell supporte :
reseau/cloud/azure/configurerapppoursharepoint.1775422278.txt.gz · Dernière modification : 2026/04/05 22:51 de techer.charles_educ-valadon-limoges.fr