No way to list `Sites.Selected` collection available for application
Describe the bug
When an app has Sites.Read.All api permission, it can list all available sites.
But when it has Sites.Selected only and was granted permissions to selected sites
via POST /v1.0/sites/{siteId}/permissions
{
"roles": [
"read"
],
"grantedToIdentities": [
{
"application": {
"id": "{clientId}",
"displayName": "Name"
}
}
]
}
There is no way to list these site available to the application:
client.sites().get().getValue();
results 0
client.sites().get(requestConfiguration -> {
requestConfiguration.queryParameters.select = new String[]{"siteCollection", "webUrl"};
requestConfiguration.queryParameters.filter = "siteCollection/root ne null";
}).getValue()
results: Access denied
client.sites().getAllSites().get().getValue();
results: Access denied
Expected behavior
Some api call which returns available via Sites.Selected
How to reproduce
- Set
Sites.Selectedpermissions to application - Add site permission to the selected collection
POST /v1.0/sites/{siteId}/permissions
{
"roles": [
"read"
],
"grantedToIdentities": [
{
"application": {
"id": "{clientId}",
"displayName": "Name"
}
}
]
}
- Call
client.sites().getAllSites().get().getValue();
observe empty result collection
SDK Version
6.10.0
Latest version known to work for scenario above?
No response
Known Workarounds
No response
Debug output
Click to expand log
```</details>
### Configuration
_No response_
### Other information
_No response_
The same empty site result list for SDK v.6.16.0 and UsernamePasswordCredential provider https://github.com/microsoftgraph/msgraph-sdk-java/issues/2184
@denysobukh @SashaUsov to double-check, is the Graph client you're instantiating to call client.sites().getAllSites().get().getValue(); using the client_id you've granted Sites.Selected permissions?
I notice that the application that creates the permission needs Sites.FullControl.All
Then you'd need to initialise a new client with the client_id passed in the payload of the request above and potentially client.sites().getAllSites().get().getValue(); should work?
@SashaUsov just noticed that getAllSites does not work with signed in users (delegated scenarios), it only supports application permissions.
@Ndiritu I have no problem with permissions, it works for SDK version 5.80.0. I trying to use site search now, but it returns error "com.microsoft.graph.models.odataerrors.ODataError: Syntax error: character '' is not valid at position 0 in "" ":
graphServiceClient.sites()
.get(requestConfiguration -> {
var queryParameters = requestConfiguration.queryParameters;
queryParameters.select = new String[]{SELECT_SITE_NAME};
queryParameters.search = "*";
})
.getValue();
since search = "*" is not valid for the new Graph version I am trying to get sites without a search query, but get empty result. But it works for Graph version 5.80.0, same client_id and user, and call:
graphServiceClient
.sites()
.buildRequest(new QueryOption("search", "*"), new QueryOption("select", "id,name"))
.get()
.getCurrentPage()
Thanks for clarifying.
Using an empty search parameter works for me @SashaUsov
graphClient.sites().get(
requestConfiguration -> {
requestConfiguration.queryParameters.search = ""
}
);
Does this help?
@Ndiritu empty search for me cause error:
com.microsoft.graph.models.odataerrors.ODataError: Expression expected at position 0 in ''.
a search query like "all" returns for me only 3 sites when Java SDK 5.80.0 returns 99 sites to which my user has access.
@SashaUsov
Please try using withUrl() to override the request URL. Does this unblock you?
graphClient.sites().withUrl("https://graph.microsoft.com/v1.0/sites?select=id,name&search=").get()
Would you also mind upgrading to the latest SDK version & sharing the failing code sample. It's not clear what properties you're selecting from your previous 6.x sample.
.withUrl("https://graph.microsoft.com/v1.0/sites?select=id,name&search=").get()
@Ndiritu withUrl() works for me, thank you!
Tell me please, will this bug be fixed in the next SDK releases?