function loadCreds() { var def = new dojo.Deferred(); var idJson, idObject; if (supports_local_storage()) { idJson = window.localStorage.getItem(credential); } else { // read from a cookie idJson = dojo.cookie(cred); } if (idJson && idJson != "null" && idJson.length > 4) { //proceed with loading credential idObject = dojo.fromJson(idJson); var token = idObject.credentials[0].token; //token that was stored //query used to test if loaded token is valid var url = "https://mygis.server.com/arcgis/rest/services/folder/service/MapServer/0/query"; var req = esri.request({ url : url, content : { where : "aField='aValue'", f : "json", token : token } }, { useProxy : false }); function success(data) { esri.id.initialize(idObject); def.resolve("valid token loaded"); } function error(error) { idObject.credentials[0].expires = 0000; //manually edit the loaded cred expireDate so the identityManager properly calls tokenService URL for new token esri.id.initialize(idObject); def.resolve("token invalid or expired"); } req.then(success, error); } else{ def.resolve("not loaded"); } return def.promise; } var firstProcess = loadCreds(); firstProcess.then(function(loadCredResults){//wait for stored credentials to load return secondProcess(); }).then(function(secondProcessResults){//wait for the secondProcess finishInit(); });
I've been looking everwhere on how to use the identity manager in legacy mode. THANK YOU!
instead of using "esriId", I needed to do "esri.id"
dbecker88 if I may ask you or others:
I'm trying for the first time to set up security. We have one service we want to use with tokens. Just http for now. (https later). We set up SQL database with some users and roles and enabled anonymous user roles.
I turned it to http following the docs - http://help.arcgis.com/en/arcgisserver/10.0/help/arcgis_server_dotnet_help/index.html#/Setting_up_us...
<Web server root>\ArcGIS\Tokens\web.config and other two files updated fine. Note.. there was no space in the second key line, make sure to check spaces pasting in the AppSettings keys!
We turned on the token service. I can get to our token service page fine with http://ourserver/tokens/gettoken.html
That generates a token fine.
However in our site and on the sample Sandbox (http://developers.arcgis.com/en/javascript/sandbox/sandbox.html?sample=widget_identitymanager_client...) ... the user / role we created for this Service fails.
I included Identity Manager and the local storage stuff from the sample (we want local storage for now, maybe proxy later..)
It pops up as it should, asks for credentials. But when I enter the user /pass it says "Unable to access the authentication service.
"
However... when I turn the service Permissions in ArcGIS Server Manager to "Everyone" it works just fine!
Interestingly though I noticed this secure service half-works on ArcGIS.com. I spied on it in F12/Firebug network connections and saw it got a token (the token at the end of the URL). However popups do not work. Even with everyone access. But that is fine, popups work with Everyone access in our site. It's only when we lock it down to the secured User that it fails, "Unable to access the authentication service."
Anyone seen this?
Called tech support, we couldn't fix it, we tried making a new user, new service/.msd, etc. Still happens. In fact I took the sample, but just stuck my secured service in it, same error. As both FeatureLayer and Dynamic. Will keep working on it, post results back...