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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added required permissions warning to Submit-PnPSearchQuery #4495

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

NishkalankBezawada
Copy link
Contributor

Type

  • Bug Fix
  • New Feature
  • Sample

Related Issues?

Fixes #X, partially fixes #Y, mentioned in #4472 and #4353, etc.

What is in this Pull Request ?

Added required permissions warning to Submit-PnPSearchQuery command.

Test scenario

  1. Removed all the API permissions on the Azure AD App
  2. Connected via Device Login using ClientID as below,
PS C:\Research\PnPCommunity\powershell> Connect-PnPOnline -ClientId xxxx -Url "https://xxxx.sharepoint.com" -DeviceLogin -LaunchBrowser -Tenant xxx
WARNING:
  
  
 Code abcdefg has been copied to your clipboard and a new tab in the browser has been opened. Please paste this
 code in there and proceed.
  
  


PS C:\Research\PnPCommunity\powershell> Submit-PnPSearchQuery -Query "contentclass:STS_ListItem_DocumentLibrary" -SelectProperties ComplianceTag,InformationProtectionLabelId -All

Submit-PnPSearchQuery: The current principal does not have permission to execute queries on behalf of other users.
PS C:\Research\PnPCommunity\powershell>
  1. Connected via App only context as below,
PS C:\Research\PnPCommunity\powershell> Connect-PnPOnline -ClientId xxxx -Url "https://xxxx.sharepoint.com" -Tenant xxxx -Thumbprint ABCDEFG
PS C:\Research\PnPCommunity\powershell> Submit-PnPSearchQuery -Query "contentclass:STS_ListItem_DocumentLibrary" -SelectProperties ComplianceTag,InformationProtectionLabelId -All

Submit-PnPSearchQuery: The remote server returned an error: (401) Unauthorized.
PS C:\Research\PnPCommunity\powershell>

After changes

  1. Connected via Device Login using ClientID as below,

PS C:\Research\PnPCommunity\powershell> Connect-PnPOnline -ClientId xxxxx -Url "https://xxxx.sharepoint.com" -DeviceLogin -LaunchBrowser -Tenant xxxx
WARNING:
  
  
 Code ABCDEF123 has been copied to your clipboard and a new tab in the browser has been opened. Please paste this
 code in there and proceed.
 
PS C:\Research\PnPCommunity\powershell> Submit-PnPSearchQuery -Query "contentclass:STS_ListItem_DocumentLibrary" -SelectProperties ComplianceTag,InformationProtectionLabelId -All
WARNING: Current access token lacks the following required delegated permission scope on the resource SharePoint Online:
Sites.Search.All

Submit-PnPSearchQuery: The current principal does not have permission to execute queries on behalf of other users.
PS C:\Research\PnPCommunity\powershell>
  1. Connected via App only context as below,
PS C:\Research\PnPCommunity\powershell> Connect-PnPOnline -ClientId xxxx -Url "https://xxxx.sharepoint.com" -Tenant xxxx -Thumbprint ABCDEFG
PS C:\Research\PnPCommunity\powershell> Submit-PnPSearchQuery -Query "contentclass:STS_ListItem_DocumentLibrary" -SelectProperties ComplianceTag,InformationProtectionLabelId -All

WARNING: Current access token lacks the following required application permission scope on the resource SharePoint Online:
Sites.Read.All


Submit-PnPSearchQuery: The remote server returned an error: (401) Unauthorized.
PS C:\Research\PnPCommunity\powershell>

Required permissions

Type API/ Permission Name Admin consent required
Application sharepoint/Sites.Read.All yes
Delegated sharepoint/Sites.Search.All yes

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

Successfully merging this pull request may close these issues.

1 participant