fix: Update SharePoint authentication and folder browser with proper permissions

This commit is contained in:
Bobby Abellana (aider) 2025-02-19 14:45:12 -08:00
parent ffdbb56aa3
commit 21bc01e3cc
2 changed files with 20 additions and 17 deletions

View File

@ -37,7 +37,6 @@ function Save-Config {
function Connect-SharePoint {
try {
# Use current form values instead of saved config
$siteUrl = $script:txtSiteUrl.Text
$clientId = $config.ClientId
$clientSecret = $config.ClientSecret
@ -46,11 +45,15 @@ function Connect-SharePoint {
throw "Please enter a Site URL"
}
Connect-PnPOnline -Url $siteUrl -ClientId $clientId -ClientSecret $clientSecret -WarningAction SilentlyContinue
Connect-PnPOnline -Url $siteUrl -ClientId $clientId -ClientSecret $clientSecret `
-WarningAction SilentlyContinue `
-Tenant "sutterhill" ` # Match your tenant name
-Scopes @("AllSites.FullControl") # Required for folder browsing
return $true
}
catch {
$script:txtStatus.Text += "Error connecting: $_`n"
$script:txtStatus.Text += "Connection Error: $($_.Exception.Message)`n"
return $false
}
}
@ -131,29 +134,28 @@ function Move-Files {
}
}
function Get-FolderBrowser {
param($context)
try {
if (-not (Connect-SharePoint)) {
return $null
}
$libraryName = $script:txtProdLib.Text
if (-not $libraryName) {
throw "Production Library name is required"
# Verify library exists and is accessible
$library = Get-PnPList -Identity $script:txtProdLib.Text -Includes RootFolder,HasUniqueRoleAssignments
if ($library.HasUniqueRoleAssignments) {
throw "This library has unique permissions - verify app has access"
}
$ctx = Get-PnPConnection
$web = Get-PnPWeb
$library = Get-PnPList -Identity $libraryName
# Get folders with elevated permissions
$ctx = Get-PnPContext
$ctx.Load($library.RootFolder.Folders)
$ctx.ExecuteQuery()
$folders = Get-PnPFolder -Url $library.RootFolder.ServerRelativeUrl -Includes Folders |
Select-Object -ExpandProperty Folders |
Select-Object Name, ServerRelativeUrl
return $folders | Out-GridView -Title "Select Folder (Double-click to select)" -PassThru
return $library.RootFolder.Folders |
Select-Object Name, ServerRelativeUrl |
Out-GridView -Title "Select Folder" -PassThru
}
catch {
$script:txtStatus.Text += "Error browsing folders: $_`n"
$script:txtStatus.Text += "Folder Error: $($_.Exception.Message)`n"
return $null
}
}

View File

@ -3,5 +3,6 @@
"ClientId": "dcb744a3-96ee-4521-bb35-9909146d3a13",
"SiteUrl": "https://sutterhill.sharepoint.com/sites/tax",
"ProductionLibrary": "Documents",
"ClientSecret": "9NR8Q~GHuB2gtdMXK0N6WbwtOFokXoXa~924Ebso"
"ClientSecret": "9NR8Q~GHuB2gtdMXK0N6WbwtOFokXoXa~924Ebso",
"TenantId": "sutterhill"
}