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.
var userName = "adminUser";
var password = "adminPassword";
var portalURL = "https://myOrg.maps.arcgis.com";
string tokenURL = portalURL + "/sharing/rest/generateToken";
var credentialTask = AuthenticationManager.Current.GenerateCredentialAsync(new Uri(tokenURL), userName, password);
credentialTask.Wait();
TokenCredential cred = credentialTask.Result;
var poralTask = ArcGISPortal.CreateAsync(new Uri(portalURL));poralTask.Wait();
ArcGISPortal portal = poralTask.Result;
var userTask = portal.FindUsersAsync(new PortalQueryParameters("username=A*"));
var users = userTask.Result;
> var userTask = portal.FindUsersAsync(new PortalQueryParameters("username=A*"));
Looks like you are not awaiting this call 🙂
Thanks PreetiMaske for your response.
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."
What version of ArcGIS Enterprise are you using?
I think the user is how you are getting the credential, the call for the Users is fine.
That is a obsolete method for getting credentials, you should really be using the OAuth pattern.
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
Thanks for your response JoeHershman.
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.
Esri has a pretty in depth sample on setting up OAuth Authentication in Mobile/AGOL located here: Access services with OAuth 2.0 This is probably the best place to start as it requires setup in AGOL in addition to the code.
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). We have switched to using OAuth in all our applications
I ended up implementing the following solution using the REST endpoints.
public class Result
{
public string UserName { get; set; }
public object UDN { get; set; }
public string ID { get; set; }
public string FullName { get; set; }
public List<string> Categories { get; set; }
public string EmailStatus { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public object PreferredView { get; set; }
public object Description { get; set; }
public string Email { get; set; }
public string UserType { get; set; }
public object IDPUsername { get; set; }
public object FavGroupId { get; set; }
public object LastLogin { get; set; }
public bool MFAEnabled { get; set; }
public bool ValidateUserProfile { get; set; }
public int StorageUsage { get; set; }
public int StorageQuota { get; set; }
public string OrgId { get; set; }
public string Role { get; set; }
public string Level { get; set; }
public string UserLicenseTypeId { get; set; }
public bool Disabled { get; set; }
public List<object> Tags { get; set; }
public string Culture { get; set; }
public object CultureFormat { get; set; }
public object Region { get; set; }
public string Units { get; set; }
public object Thumbnail { get; set; }
public string Access { get; set; }
public object Created { get; set; }
public object Modified { get; set; }
public string Provider { get; set; }
public List<object> Groups { get; set; }
}
public class Root
{
public int Total { get; set; }
public int Start { get; set; }
public int Num { get; set; }
public int NextStart { get; set; }
public List<Result> Results { get; set; }
}