<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Get List of Users from AGOL using C# .Net in .NET Maps SDK Questions</title>
    <link>https://community.esri.com/t5/net-maps-sdk-questions/get-list-of-users-from-agol-using-c-net/m-p/1321282#M12053</link>
    <description>&lt;P&gt;&lt;SPAN&gt;&amp;gt; var userTask = portal.FindUsersAsync(new PortalQueryParameters("username=A*"));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Looks like you are not awaiting this call &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 22 Aug 2023 17:47:59 GMT</pubDate>
    <dc:creator>PreetiMaske</dc:creator>
    <dc:date>2023-08-22T17:47:59Z</dc:date>
    <item>
      <title>Get List of Users from AGOL using C# .Net</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/get-list-of-users-from-agol-using-c-net/m-p/1320211#M12049</link>
      <description>&lt;P&gt;I am trying to get a list of AGOL users in my Organization, by passing the Admin User Credentials in a C# program. I would like to know how I can pass the credential to the portalTask. I am using Maps SDK for .Net version 200.1.&amp;nbsp;&lt;/P&gt;&lt;P&gt;var userName = "adminUser";&lt;BR /&gt;var password = "adminPassword";&lt;BR /&gt;var portalURL = "&lt;A href="https://myOrg.maps.arcgis.com" target="_blank"&gt;https://myOrg.maps.arcgis.com&lt;/A&gt;";&lt;BR /&gt;string tokenURL = portalURL + "/sharing/rest/generateToken";&lt;/P&gt;&lt;P&gt;var credentialTask = AuthenticationManager.Current.GenerateCredentialAsync(new Uri(tokenURL), userName, password);&lt;BR /&gt;credentialTask.Wait();&lt;BR /&gt;TokenCredential cred = credentialTask.Result;&lt;/P&gt;&lt;P&gt;var poralTask = ArcGISPortal.CreateAsync(new Uri(portalURL));poralTask.Wait();&lt;BR /&gt;ArcGISPortal portal = poralTask.Result;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;var userTask = portal.FindUsersAsync(new PortalQueryParameters("username=A*"));&lt;BR /&gt;var users = userTask.Result;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2023 17:20:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/get-list-of-users-from-agol-using-c-net/m-p/1320211#M12049</guid>
      <dc:creator>ParminderDhaliwal</dc:creator>
      <dc:date>2023-08-18T17:20:56Z</dc:date>
    </item>
    <item>
      <title>Re: Get List of Users from AGOL using C# .Net</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/get-list-of-users-from-agol-using-c-net/m-p/1321282#M12053</link>
      <description>&lt;P&gt;&lt;SPAN&gt;&amp;gt; var userTask = portal.FindUsersAsync(new PortalQueryParameters("username=A*"));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Looks like you are not awaiting this call &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Aug 2023 17:47:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/get-list-of-users-from-agol-using-c-net/m-p/1321282#M12053</guid>
      <dc:creator>PreetiMaske</dc:creator>
      <dc:date>2023-08-22T17:47:59Z</dc:date>
    </item>
    <item>
      <title>Re: Get List of Users from AGOL using C# .Net</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/get-list-of-users-from-agol-using-c-net/m-p/1321598#M12058</link>
      <description>&lt;P&gt;Thanks PreetiMaske for your response.&lt;BR /&gt;&lt;BR /&gt;I added await to the call but I am still getting the "'You do not have permissions to access this resource or perform this operation."&lt;/P&gt;</description>
      <pubDate>Wed, 23 Aug 2023 13:46:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/get-list-of-users-from-agol-using-c-net/m-p/1321598#M12058</guid>
      <dc:creator>ParminderDhaliwal</dc:creator>
      <dc:date>2023-08-23T13:46:55Z</dc:date>
    </item>
    <item>
      <title>Re: Get List of Users from AGOL using C# .Net</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/get-list-of-users-from-agol-using-c-net/m-p/1321742#M12061</link>
      <description>&lt;P&gt;What version of ArcGIS Enterprise are you using?&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think the user is how you are getting the credential, the call for the Users is fine.&lt;/P&gt;&lt;P&gt;That is a obsolete method for getting credentials, you should really be using the OAuth pattern.&lt;/P&gt;&lt;P&gt;Also as a general comment you are not using an async calls the way they are designed, should call await not have .Wait at the end of a call&lt;/P&gt;</description>
      <pubDate>Wed, 23 Aug 2023 16:47:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/get-list-of-users-from-agol-using-c-net/m-p/1321742#M12061</guid>
      <dc:creator>JoeHershman</dc:creator>
      <dc:date>2023-08-23T16:47:13Z</dc:date>
    </item>
    <item>
      <title>Re: Get List of Users from AGOL using C# .Net</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/get-list-of-users-from-agol-using-c-net/m-p/1321772#M12062</link>
      <description>&lt;P&gt;Thanks for your response JoeHershman.&amp;nbsp;&lt;BR /&gt;I am using ArcGIS Online (maps.arcgis.com). I agree my code is not correct that is why it is not working. Can you please supply any code sample to create a credential object using OAuth and attach it to portalTask or userTask.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Aug 2023 17:27:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/get-list-of-users-from-agol-using-c-net/m-p/1321772#M12062</guid>
      <dc:creator>ParminderDhaliwal</dc:creator>
      <dc:date>2023-08-23T17:27:26Z</dc:date>
    </item>
    <item>
      <title>Re: Get List of Users from AGOL using C# .Net</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/get-list-of-users-from-agol-using-c-net/m-p/1321832#M12064</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/425628"&gt;@ParminderDhaliwal&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Esri has a pretty in depth sample on setting up OAuth Authentication in Mobile/AGOL located here:&amp;nbsp;&lt;A href="https://developers.arcgis.com/net/security-and-authentication/tutorials/access-services-with-oauth-2-0/" target="_blank" rel="noopener"&gt;Access services with OAuth 2.0&lt;/A&gt;&amp;nbsp; &amp;nbsp;This is probably the best place to start as it requires setup in AGOL in addition to the code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do not think that you can use the methods that just take a user name and password to generate a credential from AGOL anymore (I may be incorrect, but that is my understanding).&amp;nbsp; We have switched to using OAuth in all our applications&lt;/P&gt;</description>
      <pubDate>Wed, 23 Aug 2023 18:53:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/get-list-of-users-from-agol-using-c-net/m-p/1321832#M12064</guid>
      <dc:creator>JoeHershman</dc:creator>
      <dc:date>2023-08-23T18:53:33Z</dc:date>
    </item>
    <item>
      <title>Re: Get List of Users from AGOL using C# .Net</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/get-list-of-users-from-agol-using-c-net/m-p/1323559#M12070</link>
      <description>&lt;P&gt;I ended up implementing the following solution using the REST endpoints.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;DIV&gt;var userName = "adminUser";&lt;/DIV&gt;&lt;DIV&gt;var password = "adminPassword";&lt;/DIV&gt;&lt;DIV&gt;var portalURL = "&lt;A href="https://myOrg.maps.arcgis.com" target="_blank"&gt;https://myOrg.maps.arcgis.com&lt;/A&gt;";&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;string tokenURL = portalURL + "/sharing/rest/generateToken";&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;var credentialTask = AuthenticationManager.Current.GenerateCredentialAsync(new Uri(tokenURL), userName, password);&lt;/DIV&gt;&lt;DIV&gt;credentialTask.Wait();&lt;/DIV&gt;&lt;DIV&gt;TokenCredential cred = credentialTask.Result;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;var client = new HttpClient();&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;int start = 1;&lt;/DIV&gt;&lt;DIV&gt;int number = 10;&lt;/DIV&gt;&lt;DIV&gt;while (start != -1)&lt;/DIV&gt;&lt;DIV&gt;{&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; string url = string.Format("{0}/sharing/rest/portals/self/users/search?start={1}&amp;amp;num={2}&amp;amp;f=json&amp;amp;token={3}", portalURL, start, number, cred.Token);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; var request = new HttpRequestMessage(HttpMethod.Post, url);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; var response = await client.SendAsync(request);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; response.EnsureSuccessStatusCode();&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; var jsonResponse = response.Content.ReadAsStringAsync().Result;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; Root? root = JsonConvert.DeserializeObject&amp;lt;Root?&amp;gt;(jsonResponse);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; foreach (Result user in root.Results)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; {&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.WriteLine(user.FullName);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; }&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; start = root.NextStart;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;}&lt;BR /&gt;&lt;BR /&gt;Here are my Root and Result classes to store the json results from the call.&lt;BR /&gt;&lt;BR /&gt;&lt;P&gt;public class Result&lt;BR /&gt;{&lt;BR /&gt;public string UserName { get; set; }&lt;BR /&gt;public object UDN { get; set; }&lt;BR /&gt;public string ID { get; set; }&lt;BR /&gt;public string FullName { get; set; }&lt;BR /&gt;public List&amp;lt;string&amp;gt; Categories { get; set; }&lt;BR /&gt;public string EmailStatus { get; set; }&lt;BR /&gt;public string FirstName { get; set; }&lt;BR /&gt;public string LastName { get; set; }&lt;BR /&gt;public object PreferredView { get; set; }&lt;BR /&gt;public object Description { get; set; }&lt;BR /&gt;public string Email { get; set; }&lt;BR /&gt;public string UserType { get; set; }&lt;BR /&gt;public object IDPUsername { get; set; }&lt;BR /&gt;public object FavGroupId { get; set; }&lt;BR /&gt;public object LastLogin { get; set; }&lt;BR /&gt;public bool MFAEnabled { get; set; }&lt;BR /&gt;public bool ValidateUserProfile { get; set; }&lt;BR /&gt;public int StorageUsage { get; set; }&lt;BR /&gt;public int StorageQuota { get; set; }&lt;BR /&gt;public string OrgId { get; set; }&lt;BR /&gt;public string Role { get; set; }&lt;BR /&gt;public string Level { get; set; }&lt;BR /&gt;public string UserLicenseTypeId { get; set; }&lt;BR /&gt;public bool Disabled { get; set; }&lt;BR /&gt;public List&amp;lt;object&amp;gt; Tags { get; set; }&lt;BR /&gt;public string Culture { get; set; }&lt;BR /&gt;public object CultureFormat { get; set; }&lt;BR /&gt;public object Region { get; set; }&lt;BR /&gt;public string Units { get; set; }&lt;BR /&gt;public object Thumbnail { get; set; }&lt;BR /&gt;public string Access { get; set; }&lt;BR /&gt;public object Created { get; set; }&lt;BR /&gt;public object Modified { get; set; }&lt;BR /&gt;public string Provider { get; set; }&lt;BR /&gt;public List&amp;lt;object&amp;gt; Groups { get; set; }&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;public class Root&lt;BR /&gt;{&lt;BR /&gt;public int Total { get; set; }&lt;BR /&gt;public int Start { get; set; }&lt;BR /&gt;public int Num { get; set; }&lt;BR /&gt;public int NextStart { get; set; }&lt;BR /&gt;public List&amp;lt;Result&amp;gt; Results { get; set; }&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 29 Aug 2023 16:58:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/get-list-of-users-from-agol-using-c-net/m-p/1323559#M12070</guid>
      <dc:creator>ParminderDhaliwal</dc:creator>
      <dc:date>2023-08-29T16:58:38Z</dc:date>
    </item>
  </channel>
</rss>

