map.addLayer(new esri.layers.ArcGISDynamicMapServiceLayer("http://ec2-54-243-148-157.compute-1.amazonaws.com/be/rest/services/v2/BERides/MapServer?token=MY_TOKEN_GOES_HERE"));
//This goes in the original map initialization function esri.setRequestPreCallback(function (e) { if (e.content && e.content.Web_Map_as_JSON) { e.content.Web_Map_as_JSON = e.content.Web_Map_as_JSON.replace(/\?token\=MY_TOKEN_GOES_HERE/g, "") } return e; });
Are you using enterprise or just ArcGIS server to do your user management? Depends on which one there, there is a generateToken service that you can use to create a short-term token.
Use a POST request and use the referral to create a token for the specific secure service that requires it.
Than in your operational layer definition, add a <token> parameter with the generate token as it's value.
You can find the specific JSON format how of to incorporate tokens into the operationalLayer in the ExportWebMap specification—ArcGIS Server
https://enterprise.arcgis.com/en/server/latest/publish-services/windows/exportwebmap-specification.h...