reseau:cloud:azure:configurerapppoursharepoint
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| reseau:cloud:azure:configurerapppoursharepoint [2026/04/05 22:51] – [Inscription d'une application] techer.charles_educ-valadon-limoges.fr | reseau: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 14: | Ligne 14: | ||
| ==== Installer Microsoft.Graph de Powershell ==== | ==== Installer Microsoft.Graph de Powershell ==== | ||
| - | | + | |
| * permissions API (Microsoft Graph) : Sites.Selected (Application) | * permissions API (Microsoft Graph) : Sites.Selected (Application) | ||
| - | | + | |
| < | < | ||
| Ligne 129: | Ligne 129: | ||
| | | ||
| - | |||
| * Export du certificat PUBLIC à importer dans Entra ID | * Export du certificat PUBLIC à importer dans Entra ID | ||
| Ligne 138: | Ligne 137: | ||
| </ | </ | ||
| - | | + | |
| + | |||
| + | * Test avec PowerShell (certificat local) | ||
| < | < | ||
| - | Add-MgApplicationKey | + | Connect-MgGraph |
| - | | + | |
| - | | + | |
| + | | ||
| + | |||
| + | => Résultat attendu | ||
| + | Plain TextWelcome To Microsoft Graph! | ||
| </ | </ | ||
| - | ===================== | + | |
| - | + | ||
| - | | + | |
| - | + | ||
| - | <WRAP center round important> | + | |
| - | Il est important de se connecter en tant qu' | + | |
| - | </ | + | |
| < | < | ||
| - | ############################################################ | + | Get-MgContext |
| - | # CONFIGURATION pour l' | + | |
| - | ############################################################ | + | |
| - | $TenantId | + | => on doit voir : |
| - | $AppId | + | |
| - | $Thumbprint = " | + | ClientId |
| + | TenantId | ||
| + | Scopes | ||
| + | AuthType | ||
| + | TokenCredentialType | ||
| + | CertificateThumbprint | ||
| + | </ | ||
| - | $SitePath | + | ==== Donner accès à l' |
| - | $NewFolderName | + | |
| + | * l' | ||
| + | < | ||
| + | # deconnexion | ||
| + | Disconnect-MgGraph | ||
| - | $SitePath = "/ | + | # Connexion admin |
| - | $NewFolderName = "Test-SitesSelected-OK" | + | Connect-MgGraph |
| - | ############################################################ | + | # Récupérer le site |
| - | # ÉTAPE 1 – OBTENIR UN TOKEN D’APPLICATION (CLIENT CREDENTIALS) | + | $site = Get-MgSite -SiteId " |
| - | ############################################################ | + | |
| - | Write-Host "Authentification par certificat…" | + | # Donner accès controle total à l' |
| + | New-MgSitePermission ` | ||
| + | -SiteId $site.Id ` | ||
| + | -Roles " | ||
| + | -GrantedToIdentities @{ | ||
| + | Application = @{ | ||
| + | Id = "ID application" | ||
| + | DisplayName = "application" | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | * Se reconnecter en AppOnly : | ||
| - | $cert = Get-Item "Cert: | + | < |
| + | Connect-MgGraph ` | ||
| + | -TenantId " | ||
| + | -ClientId " | ||
| + | -CertificateThumbprint | ||
| + | </ | ||
| - | $assertion = [Microsoft.Identity.Client.ConfidentialClientApplicationBuilder]:: | + | * Puis Tester l’accès au site précis: |
| - | WithTenantId($TenantId). | + | |
| - | WithCertificate($cert). | + | |
| - | Build() | + | |
| - | $tokenResult = $assertion.AcquireTokenForClient(@("https:// | + | < |
| - | | + | Get-MgSite -SiteId |
| + | </ | ||
| - | $Headers = @{ | ||
| - | Authorization = " | ||
| - | } | ||
| - | Write-Host "Token d' | + | ==== Créer un dossier dans le site SharePoint ==== |
| + | * Identifier le site SharePoint en itilisant le chemin direct : | ||
| - | ############################################################ | + | < |
| - | # ÉTAPE 2 – RÉCUPÉRER LE SITE SHAREPOINT PAR SON URL | + | $site = Get-MgSite -SiteId " |
| - | ############################################################ | + | $site.Id |
| - | Write-Host " | + | => Afficher le GUID du site du type : |
| + | xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx | ||
| + | </ | ||
| - | $site = Invoke-RestMethod ` | + | * Récupérer le drive du site (Documents) |
| - | -Method GET ` | + | |
| - | -Uri "https://graph.microsoft.com/ | + | |
| - | -Headers $Headers | + | |
| - | $SiteId = $site.id | + | < |
| - | + | $drive = Get-MgSiteDrive | |
| - | Write-Host "Site trouvé : $($site.displayName)" | + | $drive.Id |
| - | Write-Host " | + | |
| - | + | ||
| - | ############################################################ | + | |
| - | # ÉTAPE 3 – ATTRIBUER LA PERMISSION WRITE | + | |
| - | ############################################################ | + | |
| - | + | ||
| - | Write-Host " | + | |
| - | + | ||
| - | $permissionBody | + | |
| - | roles = @(" | + | |
| - | grantedToIdentities = @( | + | |
| - | @{ | + | |
| - | application = @{ | + | |
| - | id = $AppId | + | |
| - | } | + | |
| - | } | + | |
| - | ) | + | |
| - | } | ConvertTo-Json -Depth 5 | + | |
| - | + | ||
| - | Invoke-RestMethod ` | + | |
| - | -Method POST ` | + | |
| - | -Uri " | + | |
| - | -Headers | + | |
| - | -Body $permissionBody ` | + | |
| - | -ContentType " | + | |
| - | + | ||
| - | Write-Host " | + | |
| - | + | ||
| - | ############################################################ | + | |
| - | # É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 " | + | |
| - | -Headers $Headers ` | + | |
| - | -Body $folderBody ` | + | |
| - | -ContentType " | + | |
| - | + | ||
| - | Write-Host " | + | |
| + | => Affiche un DriveId | ||
| + | Type : documentLibrary | ||
| </ | </ | ||
| - | * Donner accès à l' | + | * Créer un dossier À LA RACINE (test simple). |
| < | < | ||
| - | Grant-MgSitePermission | + | New-MgDriveRootChild ` |
| + | | ||
| + | | ||
| + | | ||
| + | " | ||
| + | " | ||
| + | | ||
| - | Grant-MgSitePermission ` | ||
| - | -SiteId $site.Id ` | ||
| - | -Roles " | ||
| - | -GrantedToIdentities @{ application = @{ id = " | ||
| + | => Résultat attendu | ||
| + | Id : 01ABCDEF.... | ||
| + | Name : Test-Dossier | ||
| + | => Dossier créé avec succès à vérifier dans SharePoint | ||
| </ | </ | ||
| - | * Tester l’accès avec Microsoft Graph (avec client secret) | + | * lister les dossier à la racine |
| - | Variables requises | ||
| < | < | ||
| - | $tenantId | + | $items = Get-MgDriveRootChild -DriveId |
| - | $clientId | + | |
| - | $clientSecret = "< | + | |
| - | $siteId | + | |
| </ | </ | ||
| - | * Obtenir un token avec l’application | + | * Récupérer le dossier General |
| < | < | ||
| - | $tokenBody | + | $parent |
| - | client_id | + | $parent.Id |
| - | scope = " | + | </ |
| - | | + | |
| - | | + | |
| - | } | + | |
| - | * | + | * création du sous-dossier |
| < | < | ||
| - | $headers = @{ Authorization = " | + | New-MgDriveItemChild ` |
| - | $body = ' | + | -DriveId |
| - | + | -DriveItemId $parent.Id ` | |
| - | Invoke-RestMethod ` | + | -AdditionalProperties |
| - | -Uri "https:// | + | " |
| - | -Headers $headers ` | + | |
| - | -Method POST ` | + | "@microsoft.graph.conflictBehavior" |
| - | -Body $body ` | + | } |
| - | -ContentType | + | |
| </ | </ | ||
| - | |||
| ==== Installer le module module PnP.PowerShell ==== | ==== Installer le module module PnP.PowerShell ==== | ||
| PnP.PowerShell supporte : | PnP.PowerShell supporte : | ||
reseau/cloud/azure/configurerapppoursharepoint.1775422264.txt.gz · Dernière modification : 2026/04/05 22:51 de techer.charles_educ-valadon-limoges.fr
