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

expand of appRoleAssignments on user get call yields no results #2242

Open
kdejaeger opened this issue Dec 2, 2024 · 2 comments
Open

expand of appRoleAssignments on user get call yields no results #2242

kdejaeger opened this issue Dec 2, 2024 · 2 comments
Labels
Needs: Attention 👋 type:question An issue that's a question

Comments

@kdejaeger
Copy link

Describe the bug

I was trying to get a user together with it's appRoleAssignments in one call. The documentation is pointing out that the expand feature for appRoleAssignments is supported. But it doesn't work.

Expected behavior

I would expect the expand to return results.

How to reproduce

            User user = graphClient.usersWithUserPrincipalName(username).get(
                rc -> {
                    rc.queryParameters.select = new String[]{"id", "userPrincipalName", "displayName", "givenName", "surname", "accountEnabled"};
                    rc.queryParameters.expand = new String[]{"appRoleAssignments"};
                }
            );

or

graphClient.users().byUserId(username).get(
                rc -> {
                    rc.queryParameters.select = new String[]{"id", "userPrincipalName", "displayName", "givenName", "surname", "accountEnabled"};
                    rc.queryParameters.expand = new String[]{"appRoleAssignments"};
                }
            );

SDK Version

6.22.0

Latest version known to work for scenario above?

No response

Known Workarounds

For now I have to write this code to get it done:

            var user = graphClient.usersWithUserPrincipalName(username).get(
                rc -> rc.queryParameters.select = new String[]{"id", "userPrincipalName", "displayName", "givenName", "surname", "accountEnabled"}
            );
            user.setAppRoleAssignments(getAllAppRoleAssignments(user.getId())); // an 'expand' of appRoleAssignments in the above call gave an empty array :| ...
            return user;

    private List<AppRoleAssignment> getAllAppRoleAssignments(String userId) {
        var result = new ArrayList<AppRoleAssignment>();
        var page = graphClient.users().byUserId(userId).appRoleAssignments().get();
        while (page != null) {
            result.addAll(Optional.ofNullable(page.getValue()).orElse(emptyList()));
            var odataNextLink = page.getOdataNextLink();
            if (StringUtils.isBlank(odataNextLink)) {
                break;
            } else {
                page = graphClient.users().byUserId(userId).appRoleAssignments().withUrl(odataNextLink).get();
            }
        }
        return result;
    }

Debug output

Click to expand log ```
</details>


### Configuration

_No response_

### Other information

_No response_
@kdejaeger kdejaeger added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Dec 2, 2024
@Ndiritu
Copy link
Contributor

Ndiritu commented Dec 17, 2024

Hi @kdejaeger
appRoleAssignments is not a property of a User therefore an expand won't work. Please direct me to docs that point to an $expand being possible.

Getting appRole assignments is a separate API

@Ndiritu Ndiritu added type:question An issue that's a question status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Dec 17, 2024
@kdejaeger
Copy link
Author

kdejaeger commented Dec 20, 2024

It's more in the relationship section https://learn.microsoft.com/en-us/graph/api/resources/user?view=graph-rest-1.0#relationships . It litterally sais: " Represents the app roles a user is granted for an application. Supports $expand."

And in the documentation it suggests? expand works for properties and relationships: https://learn.microsoft.com/en-us/graph/query-parameters?tabs=http#expand-parameter

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Attention 👋 type:question An issue that's a question
Projects
None yet
Development

No branches or pull requests

2 participants