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

No way to list Sites.Selected collection available for application #2090

Open
denysobukh opened this issue Jul 23, 2024 · 8 comments
Open

No way to list Sites.Selected collection available for application #2090

denysobukh opened this issue Jul 23, 2024 · 8 comments
Assignees
Labels

Comments

@denysobukh
Copy link

denysobukh commented Jul 23, 2024

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

  1. Set Sites.Selected permissions to application
  2. Add site permission to the selected collection POST /v1.0/sites/{siteId}/permissions
{
    "roles": [
        "read"
    ],
    "grantedToIdentities": [
        {
            "application": {
                "id": "{clientId}",
                "displayName": "Name"
            }
        }
    ]
}
  1. 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_
@denysobukh denysobukh added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Jul 23, 2024
@denysobukh denysobukh changed the title No way to list Sites.Selected collection available for client No way to list Sites.Selected collection available for application Jul 23, 2024
@Ndiritu Ndiritu added type:question An issue that's a question and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Aug 12, 2024
@Ndiritu Ndiritu self-assigned this Aug 12, 2024
@SashaUsov
Copy link

The same empty site result list for SDK v.6.16.0 and UsernamePasswordCredential provider
#2184

@Ndiritu
Copy link
Contributor

Ndiritu commented Oct 3, 2024

@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?

@Ndiritu
Copy link
Contributor

Ndiritu commented Oct 3, 2024

@SashaUsov just noticed that getAllSites does not work with signed in users (delegated scenarios), it only supports application permissions.

@SashaUsov
Copy link

SashaUsov commented Oct 3, 2024

@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()

@Ndiritu
Copy link
Contributor

Ndiritu commented Oct 3, 2024

Thanks for clarifying.

Using an empty search parameter works for me @SashaUsov

graphClient.sites().get(
    requestConfiguration -> {
        requestConfiguration.queryParameters.search = ""
    }
);       

Does this help?

@SashaUsov
Copy link

@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.

@Ndiritu
Copy link
Contributor

Ndiritu commented Oct 3, 2024

@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.

@SashaUsov
Copy link

.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?

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

No branches or pull requests

3 participants