Hi I am trying to do Token based authentication from the user Interface of my xamarin App.
I have gone through the link Use the Authentication Manager—ArcGIS Runtime SDK for .NET | ArcGIS for Developers
But it's not clear to me,How to implement it.
My target is to generate token of ArcGis and pass that token to our webApi(Rest Service) which will authenticate that token.
Please provide me code sample how it can be achieved for ArcGis Portal.
Thanks in advance.
Please have a look to the Token Challenge sample.
Hi Here is the Solution::
Call this method inside your button click event...
private async void LogIn(string username, string password)
{
btn.IsVisible = false;
aiLogin.IsRunning = true;
if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(passw ord)){
ShowError("Invalid username or password");
return;
}
var url = "https://yourorg.maps.arcgis.com/sharing/rest";
try{
App.UserCredential = await AuthenticationManager.Current.GenerateCredentialAsync(new Uri(url), username.ToLower(), password) as ArcGISTokenCredential;
//Connect to the portal
ArcGISPortal portal = await ArcGISPortal.CreateAsync(new Uri(url), App.UserCredential, CancellationToken.None);
//Get current portal user
App.CurrentPortalUser = portal.User;
}
catch(Exception ex){
string str = ex.ToString();
System.Diagnostics.Debug.Print(str);
return;
}
}