Invalid Token for QueryTask

3916
8
02-08-2012 04:26 PM
MostafaAsadi
New Contributor
Hi,

I have a secure Map Server that I can access by typing its url and token in the address bar of my browser: http://serverurl?token=token_value. However, when I call a QueryTask, I get an "Invalid Token" error:
{"code":498,"message":"Invalid token","details":[]}


Here's how I construct and run the QueryTask:
var url = "http://serverurl?token=token_value";
var task = new esri.tasks.QueryTask(url);
var q = new esri.tasks.Query();

// set query parameters ....

task.execute(q, callbackHandler);


Can someone point out to me the possible cause for this error?
0 Kudos
8 Replies
nicogis
MVP Frequent Contributor
the token can be also expired with error 498.
0 Kudos
MostafaAsadi
New Contributor
But like I mentioned, typing the url+token in the browser authenticates with no issues. If the token was expired I wouldn't be able to open up the url in the browser. Btw I'm using the JavaScript API v1.2 if that makes a difference.

Thanks.
0 Kudos
GeorgePan
New Contributor
Did you fix it?
0 Kudos
derekswingley1
Frequent Contributor
But like I mentioned, typing the url+token in the browser authenticates with no issues. If the token was expired I wouldn't be able to open up the url in the browser. Btw I'm using the JavaScript API v1.2 if that makes a difference.


We've greatly simplified how secure services are accessed by introducing the identity manager at version 2.5. My recommendation is to upgrade your app to at least 2.5 (preferably you would upgrade to the latest version, which is 2.8) and use the identity manager to handle tokens for you.
0 Kudos
nicogis
MVP Frequent Contributor
Mo, have you done a test with api 2.8 ?
0 Kudos
danbecker
Occasional Contributor III
Mo, have you done a test with api 2.8 ?


2.8 identity manager works great for secure services, even if the service is used for find/query.

someone correct me if I'm wrong, but the only change to your code is to add:

dojo.require("esri.IdentityManager");
var facils = new esri.layers.FeatureLayer("https://mydomain.com/ArcGIS/rest/services/secured/0",{
    mode:esri.layers.FeatureLayer.MODE_ONDEMAND,
    outFields:["*"]
});
0 Kudos
derekswingley1
Frequent Contributor
2.8 identity manager works great for secure services, even if the service is used for find/query.

someone correct me if I'm wrong, but the only change to your code is to add:

dojo.require("esri.IdentityManager");
var facils = new esri.layers.FeatureLayer("https://mydomain.com/ArcGIS/rest/services/secured/0",{
    mode:esri.layers.FeatureLayer.MODE_ONDEMAND,
    outFields:["*"]
});


That's great! And yes, that's all you need to do in your code to use the identity manager. What's stopping you from upgrading to 2.8?
0 Kudos
MostafaAsadi
New Contributor
We have used the Sample JavaScript Viewer as template for our work and now upgrading to v2.8 is going to be painful, especially that I have no idea what needs to change.
0 Kudos