Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to approve a SPFx app permission request with PnP Powershell #9633

Open
9 tasks
mmohapatra-muhimbi opened this issue Apr 11, 2024 · 0 comments
Open
9 tasks

Comments

@mmohapatra-muhimbi
Copy link

mmohapatra-muhimbi commented Apr 11, 2024

What type of issue is this?

Question

What SharePoint development model, framework, SDK or API is this about?

馃挜 SharePoint Framework

Target SharePoint environment

SharePoint Online

What browser(s) / client(s) have you tested

  • 馃挜 Internet Explorer
  • 馃挜 Microsoft Edge
  • 馃挜 Google Chrome
  • 馃挜 FireFox
  • 馃挜 Safari
  • mobile (iOS/iPadOS)
  • mobile (Android)
  • not applicable
  • other (enter in the "Additional environment details" area below)

Additional environment details

SPFx version 1.18.2
Node 18.9.0
Powershell: 7.4.1
PnP.PowerShell 2.4.33

Issue description

We have some webApiPermissionRequests defined in spfx package-solution json file

"webApiPermissionRequests": [
      {
        "resource": "Azure AD app name",
        "scope": "user_impersonation"
      },
      {
        "resource": "Microsoft Graph",
        "scope": "User.Read, AllSites.FullControl"
      }
    ]
In PowerShell I am trying to approve these permission requests using
$permissionRequests = Get-PnPTenantServicePrincipalPermissionRequests
    foreach ($req in $permissionRequests)
        {
            if ($req.PackageName -eq "$muhimbiPackageName")
            {
                Write-Host "Granting permissions $($req.Name) $($req.Scope)"

                Approve-PnPTenantServicePrincipalPermissionRequest -RequestId $req.Id -Force -ErrorAction SilentlyContinue -ErrorVariable approveRequestError -OutVariable approveRequestResult | Out-Null

                if (![String]::IsNullOrWhiteSpace($approveRequestError) -And -Not($approveRequestError -imatch "already exists"))
                {
                    Write-Host "approveRequestError: $approveRequestError"
                    $grantedAllPermissions = $false;
                    Write-Host "Failed" -ForegroundColor Red
                }
                else
                {
                    Write-Host "Success" -ForegroundColor Green
                }

                Write-Host ""
            }
        }

But I am getting below error:
approveRequestError: The service principal for permssion request {SPFX_App_Name} could not be found.

Please note there is a typo in "permssion"

Script was working fine few days ago but started giving error recently

I tried the SP online powershell as well
Get-SPOTenantServicePrincipalPermissionRequests and Approve-SPOTenantServicePrincipalPermissionRequest
getting same error

Tried
Enable-SPOTenantServicePrincipal it gives us "Unknown Error"

I checked below service principal exists:

  1. "SharePoint Online Client Extensibility Web Application Principal"
  2. "GraphAggregatorService" or "Microsoft Graph"
  3. Azure AD app created by us

Manually approving the permission works just fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant