c# - Azure AD Graph API Group Search -
we have office365 account active directory on azure. making search feature queries our azure ad given search term. since graph api supports .startswith(string) linq queries, have pull in groups query collection search term.
i using 'get group members' function this demo guide make search function.
here code:
public list<mymodel> searchgroups(string term) { list<mymodel> returnlist = new list<mymodel>(); //my service root uri uri serviceroot = new uri(servicerooturl); //create client , authorization activedirectoryclient adclient = new activedirectoryclient(serviceroot, async () => await getapptokenasync()); //get collection of igroup ipagedcollection<igroup> groups = adclient.groups.executeasync().result; //do while loop because groups returned in paged list... { list<igroup> directoryobjects = groups.currentpage.tolist(); //get groups contain search term foreach (igroup item in directoryobjects.where(x=>x.displayname.tolower().contains(term.tolower()))) { returnlist.add(new mymodel(item microsoft.azure.activedirectory.graphclient.group)); } //get next page of results groups = groups.getnextpageasync().result; } while (groups.morepagesavailable); //also tried while(groups != null) same issue return returnlist; }
if let run, code gets hung , never returns , if pause it, stuck on line
groups = groups.getnextpageasync().result;
if put break point , step through code, works fine thinking issue async methods. have no experience async methods , graph api docs not great in opinion stuck.
using: asp.net mvc, c#, azure active directory graph api, web api
please not use .result() prone deadlocks! in instance use await keyword async calls. if go async programming should make whole call async though. trying make async, synchronous bad practice
Comments
Post a Comment