C
C#8mo ago
<Alex>

❔ Using Microsoft Graph to verify users exist based on IEnumerable<Guid>

I am trying to work with Microsoft Graph to verify that each guid in some list is associated with a user in the graph. I have noticed that there is some sort of property graphClient.Users.GetByIds that I intuitively think I can use to at least return a list of Users somehow, but I have no idea how it’s supposed to work, and I can’t seem to find documentation on it online that is useful. Mostly I am just very confused about how this API is supposed to work at all, and to me it’s just very unintuitive. Right now the best implementation I can come up with is to call graphClient.Users[guid.ToString()].GetAsync() with a config specifying that I don’t want any data returned. I do this for every Guid in my list, and I check if an exception is thrown. This seems kind of dumb to me, but it’s the only thing I can find that actually works. To be clear, I am writing an async Task<bool> method that accepts an IEnumerable<Guid>. It should return false if any supplied Guid is not associated with a user Id in the graph, and true if every Guid is associated with a user. I feel like there has to be a more intelligent solution than what I am currently using. Any help would be appreciated.
10 Replies
Erroneous Fatality
This could help you: https://learn.microsoft.com/en-us/graph/api/user-list?view=graph-rest-1.0&tabs=http You can call List and use the $filter parameter to filter by ids, and $select parameter to also only return the id properties, to reduce network load. You could maybe also use the count method with $filter. You put your id collection into the $filter, say you want to count only users whose Id is in the $filter, and then in memory you just check if the count of Ids is equal to the result count from the request
<Alex>
<Alex>8mo ago
I’m reading through it and it seems like there might be a good answer here. I’m trying to figure out how to apply the filter in C# now.
Erroneous Fatality
I can't seem to find if the AD has filtering capability of property in (value1, value2). If not, you'd have to transform your list of Ids into a list of string commands and then join them for the filter. Something like this:
IEnumerable<Guid> ids;
IEnumerable<string> idEquations = ids.Select(id => $"c/id eq '{id}'");
string idsFilter = string.Join(" and ", idEquations);
string filter = $"identities/any(c:{idsFilter})";
IEnumerable<Guid> ids;
IEnumerable<string> idEquations = ids.Select(id => $"c/id eq '{id}'");
string idsFilter = string.Join(" and ", idEquations);
string filter = $"identities/any(c:{idsFilter})";
Then use that for the filter parameter, and for the select just use id. Then when you get your results back, you can compare the two collections of Ids and figure out which ones are not present in the AD. This is all ad-libbed, I've never used AD before now, I was just curious ><
<Alex>
<Alex>8mo ago
Yeah. I wish the documentation was better for this API. I’m so confused. Like. I still dont understand exactly what the datatype of graphClient.Users even is or how the [] operator works on it. Like, I initially thought it was like a dictionary, but I guess it isn’t. I’ll work on this later and let you know how it goes.
Erroneous Fatality
Good luck 😄 You've got C# example snippets in the documentation page (https://learn.microsoft.com/en-us/graph/api/user-list?view=graph-rest-1.0&tabs=csharp#tabpanel_2_csharp)
<Alex>
<Alex>8mo ago
Use the filter query parameter to filter a collection of objects - ...
Learn how to use the filter OData query parameter and its operators against different types of properties in Microsoft Graph.
<Alex>
<Alex>8mo ago
Thanks for your direction by the way. I saw that page you posted earlier today, but I dismissed it until you pointed it out again. Thanks.
not guilty
not guilty8mo ago
when i have to deal with graph i look at net client with ilspy and compare it with docs and powershell client to try understand something and especially i try with graph explorer to verify all the stuff there are a discord group and a microsoft forum on this subject but usually they are not very active/useful
Erroneous Fatality
Glad to have helped 🙂
Accord
Accord8mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts
✅ How to register a onNavigate/navigation event callback in Net8 SSR?blazor.web.js replaced the entire html on navigate with the response, but scripts like `<script src=❔ Establishing a connection to SQL Server in Mac (Azure data studio & Docker desktop)Ive been stuck on this error: A network-related or instance-specific error occurred while establish✅ Reading matricies to an output fileI am trying to read the data inside two matricies from an input file firstly in order to add them to❔ How to Deploy WASM Project with .NET Backend in same repo?I have a Blazor frontend with a .NET backend. How do I use Azure to deploy these when they are in th❔ EF Core LINQ translation documentIn the process of upgrading a .NET Core 1.1 to 6 app, our EF Core LINQ queries are now hitting some Is there a better (or more appropriate way) of implementing method overloading for my usecase here?I have two methods of a class I'm writing - in one usecase I want to update the field with no return❔ Referencing new projects with the main projectLet's say I have a main project `CoreProject` and I want to add 2 new projects: a `LoggerService` an❔ Refactoring strategy pattern to a simpler codeI have the following code and I want te refactor it to a less-boiler-plate code. Wha'ts suposed to❔ Avoid "Authorizing..." in Blazor Page (Identity)I am trying to avoid the loading text "Authorizing..." when going to my index.razor page. I have add❔ Trying to return```csharp using System; using System.Drawing; using System.Windows.Forms; using AForge.Imaging; usin