I have reviewed many discussions on this forum where a desire is expressed to refresh access tokens using JavaScript. I have not found an elegant solution.
Is there a better way? Just updating the .url property of a layer with a fresh token does not work. A not very elegant way to change a token is to use method removeLayer followed by method addLayer with a url string that includes a fresh token ( many undesirable side effects ).
I want to manage access based on credentials entered on my login page. On Windows platform running IIS, It is easy to get a fresh token string from a process running in the same IIS Session used by login page with all sensitive credentials safe as Session variables. A fresh token string can easily be obtained by JavaScript in a subsequent map web page run in the same session with a new layer added using this token part of the url parameter. What is surprisingly not easy is to update an existing map layer's access token. I do not understand how to best do this using esri.map JavaScript API documentation.
Solved! Go to Solution.
Joel, Great job of sleuthing! Perhaps ESRI will someday support a documented method to update token. At least while version 3.12 is around there is now an alternative to "new" layer.