In the MS Graph Java SDK 6.1, I am trying to determine the owners of a given application. I have the application ID.
I am trying to use this sample code
// Fetch the owners of the application
List<DirectoryObject> owners = graphClient
.applications(applicationId)
.owners()
.buildRequest()
.get()
.getCurrentPage();
However, applications no longer takes a parameter applicationId, and applicationsByAppId(appId) does not have a method owners().
All of my searches have returned the above code, so clearly the SDK has changed very recently. None of the samples in the SDK docs deal with this either.
I've also tried this code below, where the SDK does have the getOwners method, but it always returns null despite the application clearly having multiple owners specified.
ApplicationCollectionResponse resp = graphClient.applications().get(requestConfiguration -> {
requestConfiguration.queryParameters.select = new String[] { "id", "displayName", "appId", "passwordCredentials" };
});
results = new ArrayList<>();
List<Application> apps = resp.getValue();
while (apps != null && apps.size() > 0) {
for (Application app : apps) {
// Fetch the owners of the application
if (app.getOwners() != null) {
for (DirectoryObject dirobj : app.getOwners()) {
logger.debug("App {} has owner {}", app.getDisplayName(), dirobj.getId());
}
}
I'm afraid it requires two steps:
appId
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
Application app = graphClient.applicationsWithAppId("{appId}").get();
DirectoryObjectCollectionResponse owners = graphClient.applications().byApplicationId(app.getId()).owners().get();