I have this function, which is called from MainWindow():
private async void GenerateToken()
{
//Get token to be used for secure access
IdentityManager.Current.DefaultReferer = "BlahBlah";
IdentityManager.Current.ChallengeMethodEx += SignInDialog.DoSignInEx;
IdentityManager.Credential crd = await IdentityManager.Current.GenerateCredentialTaskAsync("http://GisServer:6080/arcgis/rest/services", "user", "pwd");
if (crd != null)
IdentityManager.Current.AddCredential(crd);
else
throw new Exception("Unknown error");
}
The application invokes geoprocessing service tasks (Geoprocessor.SubmitJobAsync()) and some of those tasks can run for a very long time, so I would rather just request a token, which does not time out for like a week or something like that.
On the GIS server I have the short lived tokens set to 60 minutes and the long lived tokens set to 1 day. I plan to change the latter to 30 days, but I do not know how to request a token like that.
Also: Does this line look sensible:
IdentityManager.Current.ChallengeMethodEx += SignInDialog.DoSignInEx;
?
It is adapted from this forum post. I do not ever want users to see any sign in dialogs. The credentials will either be hardcoded or in a config file or something like that.
Solved! Go to Solution.
I actually got this to work:
async Task GenerateToken(string tokenUrl)
{
IdentityManager.Current.DefaultReferer = "BlahBlah";
IdentityManager.Current.ChallengeMethodEx += SignInDialog.DoSignInEx;
var options = new IdentityManager.GenerateTokenOptions();
option.TokenValidity = 120;
IdentityManager.Credential crd = await IdentityManager.Current.GenerateCredentialTaskAsync(tokenUrl, _usename, _password, options);
if (crd != null)
IdentityManager.Current.AddCredential(crd);
else
throw new Exception("Unknown error");
}
I actually got this to work:
async Task GenerateToken(string tokenUrl)
{
IdentityManager.Current.DefaultReferer = "BlahBlah";
IdentityManager.Current.ChallengeMethodEx += SignInDialog.DoSignInEx;
var options = new IdentityManager.GenerateTokenOptions();
option.TokenValidity = 120;
IdentityManager.Credential crd = await IdentityManager.Current.GenerateCredentialTaskAsync(tokenUrl, _usename, _password, options);
if (crd != null)
IdentityManager.Current.AddCredential(crd);
else
throw new Exception("Unknown error");
}