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;
}
}