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

Prochaine révision
Révision précédente
reseau:cloud:azure:configurerapppoursharepoint [2026/04/05 22:08] – créée 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 1: Ligne 1:
-==== Infrastructure réalisée ====+====== Configurer une application enregistrée dans Entra ID pour gérer une équipe Sharepoint ======
  
-Documenso => MinIO => rclone (bidirectionnel) <=> Equipe Teams (API Graph)+===== Inscription d'une application =====
  
-<WRAP center round info> 
-La création d’applications pour Microsoft 365, pour accéder aux données et services de Microsoft 365, ou pour permettre aux utilisateurs de se connecter à l'application créée via leur compte professionnel ou scolaire, il est nécessaire d’**inscrire l’application** dans Entra ID. 
- 
-L'inscription d’application enregistre l'application auprès du Microsoft Entra ID et définit des paramètres tels que les permissions API ou les flux d’authentification. 
  
 Une inscription d’application dans Entra se fait :  Une inscription d’application dans Entra se fait : 
   * depuis le **portail Azure**,   * depuis le **portail Azure**,
   * en **CLI/script** avec l'**API Microsoft Graph** par exemple en utilisant **Powershell**.   * en **CLI/script** avec l'**API Microsoft Graph** par exemple en utilisant **Powershell**.
-</WRAP>+
  
 ===== Installer le module Microsoft.Graph de Powershell===== ===== Installer le module Microsoft.Graph de Powershell=====
Ligne 18: Ligne 14:
 ==== Installer Microsoft.Graph de Powershell ==== ==== Installer Microsoft.Graph de Powershell ====
  
- +  * prérequis : 
-    * prérequis : +
         * permissions API (Microsoft Graph) : Sites.Selected (Application)         * permissions API (Microsoft Graph) : Sites.Selected (Application)
  
-    * ouvrir une session Powershell en tant, qu'administrateur+  * ouvrir une session Powershell en tant, qu'administrateur
  
 <code> <code>
Ligne 35: Ligne 30:
     * Portail Azure => Entra ID     * Portail Azure => Entra ID
     * Inscription d'applications => Nouvelle inscription     * Inscription d'applications => Nouvelle inscription
-    * Nom : minio-S3+    * Nom : app
     * Locataire unique seulement     * Locataire unique seulement
     * S'incrire     * S'incrire
Ligne 42: Ligne 37:
     * Tenant ID     * Tenant ID
     * Client ID     * Client ID
-    * Ajouter un secret Client (dans Certificates & Secrets)+    * l'ajout du certificat se fera ultérieurement (dans Certificates & Secrets)
  
   * Ajouter la permission Microsoft Graph :   * Ajouter la permission Microsoft Graph :
     * Autorisations d'application (et non Autorisations déléguées) :      * Autorisations d'application (et non Autorisations déléguées) : 
       * Sites.Selected       * Sites.Selected
-      * Sites.FullControl.All (temporaire pour attribuer l'accès puis la retirer ) 
-      * Files.Read.All 
-      * Files.ReadWrite.All 
- 
  
 <WRAP center round> <WRAP center round>
-Les permissions **Files.Read.All** et **Files.ReadWrite.All** donnent l’accès à toutes les bibliothèques pour lesquelles l'App est autorisée, mais la permission **Sites.Selected** restreint l'accès au site explicitement autorisé via Graph.+La permission **Sites.Selected** restreint l'accès au site explicitement autorisé via Graph.
 </WRAP> </WRAP>
  
 <WRAP center round info> <WRAP center round info>
-Une autorisation d'application ne nécessite de compte utilisateur :+Une autorisation d'application ne nécessite pas de compte utilisateur :
   * L'application agit en autonomie (service, script, automatisation).   * L'application agit en autonomie (service, script, automatisation).
   * Nécessite un consentement administrateur.   * Nécessite un consentement administrateur.
 </WRAP> </WRAP>
  
-  * Grant admin consent. +  * Demander le consentement de l'administrateur.
- +
-  * Adresse email 0365 utilisée pour l’envoi  afin que l'app puisse avoir le droit d’envoyer au nom de ce compte.+
  
 ==== En CLI ==== ==== En CLI ====
Ligne 85: Ligne 74:
  
 <code> <code>
-$app = New-MgApplication -DisplayName "Minio-Sharepoint"+$app = New-MgApplication -DisplayName "Application"
 </code> </code>
  
Ligne 94: Ligne 83:
 </code> </code>
 ===== Autoriser l'app enregistrée à mettre à jour les dossiers de l'équipe Teams ===== ===== Autoriser l'app enregistrée à mettre à jour les dossiers de l'équipe Teams =====
-Cela ne peut se faire depuis l'interface d'administration Entra ID mais en utilisant Powershell.+Cela ne peut pas se faire depuis l'interface d'administration Entra ID mais en utilisant Powershell.
  
  
Ligne 103: Ligne 92:
 <code> <code>
 $cert = New-SelfSignedCertificate ` $cert = New-SelfSignedCertificate `
-  -Subject "CN=minio-s3" ` +  -Subject "CN=applicaton" ` 
-  -CertStoreLocation "Cert:\LocalMachine\My" `+  -CertStoreLocation "Cert:\CurrentUSer\My" `
   -KeySpec Signature `   -KeySpec Signature `
   -KeyUsage DigitalSignature `   -KeyUsage DigitalSignature `
-  -KeyExportPolicy NonExportable `+  -KeyExportPolicy Exportable `
   -HashAlgorithm SHA256 `   -HashAlgorithm SHA256 `
   -KeyLength 2048 `   -KeyLength 2048 `
Ligne 118: Ligne 107:
 </code> </code>
  
-  * Notez l'empreinte du certfifcat+  * Notez l'empreinte du certficat
  
 <code> <code>
Ligne 124: Ligne 113:
 </code> </code>
  
-  * Vérifier que le certificat est BIEN présent au BON endroit dans Cert:\LocalMachine\My+  * Vérifier que le certificat est BIEN présent au BON endroit dans Cert:\CurrentUser\My
  
 <code> <code>
-Get-Item "Cert:\LocalMachine\My\<TON_THUMBPRINT>"+Get-Item "Cert:\CurrentUSer\My\<TON_THUMBPRINT>"
 </code> </code>
  
Ligne 133: Ligne 122:
  
 <code> <code>
-$cert = Get-Item "Cert:\LocalMachine\My\<THUMBPRINT>"+$cert = Get-Item "Cert:\CurrentUSer\My\<THUMBPRINT>"
 $cert.HasPrivateKey $cert.HasPrivateKey
 </code> </code>
Ligne 139: Ligne 128:
 $cert.HasPrivateKey doit renvoyer True $cert.HasPrivateKey doit renvoyer True
  
-   exporter le certificat+   
 +  Export du certificat PUBLIC à importer dans Entra ID
  
 <code> <code>
 +Export-Certificate `
 +    -Cert "Cert:\CurrentUSer\My\$($cert.Thumbprint)" `
 +    -FilePath "application.cer"
 +</code>
  
-Export-PfxCertificate ` +  * importer le certificat dans l'application à partir du portail Azure
-  -Cert $cert ` +
-  -FilePath "$env:TEMP\minio-s3.pfx"+
-  -Password (ConvertTo-SecureString -String "TempPwd123!" -AsPlainText -Force)+
  
-</code>  +  Test avec PowerShell (certificat local)
-  +
-  importer dans user+
  
 <code> <code>
-Import-PfxCertificate ` +Connect-MgGraph `   
-  -FilePath "$env:TEMP\minio-s3.pfx" ` +   -TenantId "<TENANT_ID>" `   
-  -CertStoreLocation Cert:\CurrentUser\My ` +   -ClientId "<APP_ID>" `   
-  -Password (ConvertTo-SecureString -String "TempPwd123!-AsPlainText -Force)+   -CertificateThumbprint "<THUMBPRINT> 
 + 
 +=> Résultat attendu 
 +Plain TextWelcome To Microsoft Graph!
 </code> </code>
  
-   vérifier+  Puis :
  
 <code> <code>
-Get-ChildItem Cert:\CurrentUser\My | +Get-MgContext
-Where-Object Thumbprint -eq "<THUMBPRINT>" +
-</code>+
  
-  * Export du certificat PUBLIC à importer dans Entra ID+=> on doit voir :
  
-<code+ClientId               : <id client
-Export-Certificate ` +TenantId               : <ID tenant> 
-    -Cert "Cert:\LocalMachine\My\$($cert.Thumbprint)" ` +Scopes                 {Sites.Selected} 
-    -FilePath "minio-s3.cer"+AuthType               : AppOnly 
 +TokenCredentialType    : ClientCertificate 
 +CertificateThumbprint  : <empreinte>
 </code> </code>
  
-==== Installer PowerShell 7 ====+==== Donner accès à l'application sur le site Sharepoint====
  
-==== Installer le module Microsoft.Graph ==== +   l'administrateur doit donner l'accès au site voulu
-    prérequis :  +
-        * permissions API (Microsoft Graph) : Sites.Selected (Application) +
- +
-    * ouvrir une session Powershell en tant, qu'administrateur+
  
 <code> <code>
-Install-Module Microsoft.Graph  +# deconnexion 
-Import-Module Microsoft.Graph +Disconnect-MgGraph
-</code>+
  
 +# Connexion admin
 +Connect-MgGraph -Scopes "Sites.FullControl.All"
  
-  * script Powershell pour se conncter t etest la création d'un dossier +# Récupérer le site 
 +$site = Get-MgSite -SiteId "mondomaine.sharepoint.com:/sites/MonSite"
  
-<WRAP center round important> +# Donner accès controle total à l'application (fullcontrol / read / write) 
-Il est important de se connecter en tant qu'application et non en tant qu'utilisateur+New-MgSitePermission ` 
-</WRAP>+  -SiteId $site.Id ` 
 +  -Roles "fullcontrol"
 +  -GrantedToIdentities @{ 
 +      Application = @{ 
 +          Id = "ID application" 
 +          DisplayName = "application" 
 +      } 
 +  } 
 +</code> 
 +  
 +  * Se reconnecter en AppOnly :
  
 <code> <code>
-############################################################ +Connect-MgGraph `   
-# CONFIGURATION pour l'accès avec l'application enregistrée +    -TenantId "1ae69c2d-61b2-4de4-84c7-2a4dd0de7330" `   
-############################################################+    -ClientId "5c82fc87-6e0c-413f-ac12-6d784af9a249" `   
 +    -CertificateThumbprint "97F825CFD5C0371D28E1D691140A084B9C2C4386" 
 +</code>
  
-$TenantId     = "Tenant_educ-valadon# +  * Puis Tester l’accès au site précis:
-$AppId        = "APP_ID_DE_TON_APPLICATION"+
  
-$Thumbprint = "EMPREINTE_DU_CERTIFICAT"+<code> 
 +Get-MgSite -SiteId "mondomaine.sharepoint.com:/sites/MonSite" 
 +</code>
  
-$SitePath      = "/sites/Signaturesnumriques" 
-$NewFolderName = "Test-SitesSelected-Cert-OK" 
  
 +==== Créer un dossier dans le site SharePoint ====
  
 +  * Identifier le site SharePoint en itilisant le chemin direct :
  
-$SitePath = "/sites/Signaturesnumriques+<code> 
-$NewFolderName = "Test-SitesSelected-OK"+$site Get-MgSite -SiteId "mondomaine.sharepoint.com:/sites/MonSite
 +$site.Id
  
-############################################################ +=> Afficher le GUID du site du type : 
-# ÉTAPE 1 – OBTENIR UN TOKEN D’APPLICATION (CLIENT CREDENTIALS) +xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx 
-############################################################+</code>
  
-Write-Host "Authentification par certificat…"+   * Récupérer le drive du site (Documents) : chaque site a une document library principale.
  
-$cert = Get-Item "Cert:\LocalMachine\My\$Thumbprint" +<code> 
- +$drive = Get-MgSiteDrive -SiteId $site.Id 
-$assertion = [Microsoft.Identity.Client.ConfidentialClientApplicationBuilder]::Create($AppId). +$drive.Id
-    WithTenantId($TenantId). +
-    WithCertificate($cert). +
-    Build() +
- +
-$tokenResult = $assertion.AcquireTokenForClient(@("https://graph.microsoft.com/.default")). +
-    ExecuteAsync().GetAwaiter().GetResult() +
- +
-$Headers = @{ +
-    Authorization = "Bearer $($tokenResult.AccessToken)" +
-+
- +
-Write-Host "Token d'application obtenu via certificat" +
- +
- +
-############################################################ +
-# ÉTAPE 2 – RÉCUPÉRER LE SITE SHAREPOINT PAR SON URL +
-############################################################ +
- +
-Write-Host "Récupération du site SharePoint..." +
- +
-$site = Invoke-RestMethod ` +
-    -Method GET ` +
-    -Uri "https://graph.microsoft.com/v1.0/sites/educvaladonlimogesfr.sharepoint.com:$SitePath"+
-    -Headers $Headers +
- +
-$SiteId $site.id +
- +
-Write-Host "Site trouvé : $($site.displayName)" +
-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.1775419739.txt.gz · Dernière modification : 2026/04/05 22:08 de techer.charles_educ-valadon-limoges.fr