Hello all,I'm working with the new Spatial Analysis Services. Specifically FindNearest at "http://analysis.arcgis.com/arcgis/rest/services/tasks/GPServer/FindNearest"When I submit my job to this url by clicking a button I'm prompted to login to AGOL by the IdentityManager. I'd like to either prompt for login when the app loads, or better yet just suppress the sign in all together and login with a developer account I've created.Using IdentityManager and a ServerInfo object, I can prompt the user to login when the app loads. I then register the returned token with the IdentityManager. However, when I call my FindNearest function I get an error about access control allow origin and the request fails. My app is hosted locally. I've tried adding "analysis.arcgis.com" to esri.config.defaults.io.corsEnabledServers to no avail. XMLHttpRequest cannot load http://analysis.arcgis.com/arcgis/rest/services/tasks/GPServer/FindNearest/�?�OPERATOR%20LIKE%20%27%.... No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. I'm pretty sure analysis.arcgis.com is CORS enabled. So I'm guessing my ServerInfo is not set up correctly and I'm not generating a valid token/credentials to access analysis.arcgis.com.
esri.config.defaults.io.useCors = true;
esri.config.defaults.io.corsEnabledServers.push("analysis.arcgis.com");
//esriConfig.defaults.io.proxyUrl = "http://localhost/esriProxy/proxy.ashx?"
esri.config.defaults.io.proxyUrl = "http://localhost/esriProxy/";
var server = new ServerInfo({
server: "http://analysis.arcgis.com",
tokenServiceUrl: "https://www.arcgis.com/sharing/generateToken"
// I saw the below on my esri.id.server
//adminTokenServiceUrl: "http://analysis.arcgis.com/arcgis/admin/generateToken"
})
var loginDeferred = esri.id.signIn("http://analysis.arcgis.com", server);
loginDeferred.then(function (response) {
esri.id.registerToken(response);
})
$("#searchButton").click(function () {
var gp = new Geoprocessor("http://analysis.arcgis.com/arcgis/rest/services/tasks/GPServer/FindNearest");
var params = //skipped for space but I know these are fine
gp.submitJob(params, completeCallback);
}
I've also tried using a proxy in the event that CORS isn't working but can't seem to crack that either. Still get the CORS error message.
<?xml version="1.0" encoding="utf-8" ?>
<ProxyConfig allowedReferers="*"
mustMatch="true">
<serverUrls>
<serverUrl url="http://services.arcgisonline.com"
matchAll="true"/>
<serverUrl url="http://analysis.arcgis.com"
matchAll="true"/>
</serverUrls>
</ProxyConfig>
I'm doing at least one thing wrong...Cheers,James