I want to use tokens with a short expire time, generate a new token before expire, and then replace credentials for layers in a map.
My problem is how to prevent ArcGIS Identity Manager from continuing to create a pop-up requesting credentials.
I start with dom.byId('tokenText').value as a token having a short expire time. I start a JavaScript timer giving 30 seconds to create a new token.
I try to update credentials; I'm not sure I know what I'm doing... Pop-ups from Identity Manager occurs anyway.
Here is the "guts" of my work; any suggestions will be cheerfully accepted!
var tokenText,layerSource;
...
ready(function() {
function renewToken(urlOfMapService){
xhr.get({
// The URL of the request
url: "refreshToken.aspx",
// Allow 10 seconds to get new token
timeout: 10000,
// Send the existing token
content: {
token: tokenText
},
// The success callback with result from server
load: function(result) {
//--- result is a Comma Separated Value string of creatTime, expireTime, tokenText
var dataArray = result.split(',');
dataArray.push(urlOfMapService);
//--- UPDATE CREDENTIALS
initializeCredentials( dataArray );
app.map.getLayer("Warblers").credential = credential;
},
// The error handler
error: function(message) {
alert("error:"+message);
}
});
}
function initializeCredentials(a) {
//--- a is Array of creatTime, expireTime, tokenText, resourceURL
//--- call renewToken before expire
waitTime = parseInt(a[1],10)
- parseInt(a[0],10)
- 30000;
credentialsTimer = setTimeout(function(){renewToken(DGIFData)}, waitTime );
//--- fwisCredentials is a global Object variable assigned using JSON in a loaded script
tokenText = a[2];
credential = fwisCredentials.credentials[0];
credential.creationTime = a[0];
credential.expires = a[1];
credential.token = tokenText;
credential.resources.push(a[3]);
fwisCredentials.credentials = [credential];
kernel.id.initialize(fwisCredentials);
}
esri.config.defaults.io.proxyUrl = "https://my.server.com/proxypage_net/proxy.ashx";
layerSource = "https://my.server.com/arcgis/rest/services/Test/Warblers/MapServer";
//--- initial token and times are available at ready event
tokenText = dom.byId('tokenText').value;
initializeCredentials( [
dom.byId('tokenCreateTime').value,
dom.byId('tokenExpireTime').value,
tokenText,
layerSource
]);
app.map = new esri.Map("map", {
center: [-78.839150, 38.061840],
zoom: 7,
basemap: "topo",
slider: true,
showAttribution:true,
logo: false,
autoResize: true
});
//===LAYER LIST AND MAP SERVICES=======================================================================================
var layerObject = new ArcGISDynamicMapServiceLayer(layerSource,
{ id: "Warblers", opacity: .8 });
var flRegions = new FeatureLayer("https://my.server.com/arcgis/rest/services/Public/Agency_Public/FeatureServer/9", {
mode: FeatureLayer.MODE_ONDEMAND
});
app.map.addLayers([flRegions, layerObject]);
}); // ready function end