We are trying to get an ArcGIS Javascript map running with secured services.
We wish to manage the authentication separately, Once a user is logged into our system, they should not be presented with any authentication prompts.
With the Silverlight API we simply added a Token to the Layer.
We are having difficulties with the Javascript API.
Please refer to this URL for a sample : http://jsfiddle.net/caseycupp/4f34s5ct/6/
// Test 1 - Adding unsecured service : This works. I'm adding one layer to the map and the legend.
// Test 2 - Testing service with token : If I comment line 77 and uncomment line 79 to try to add a Secure Layer instantiated with a token to the legend. The layer is added to the map but not the legend
// Test 3 - Testing service with token : If I revert to Test 1(uncomment line 77 and comment 79) and then uncomment the section from 50-57 the credential object never gets added to the layer. (as you can see the alert fails)
Instead of adding the logic to get a token to your javascript app you should setup and use the proxy pages provided in the following github repo. This code takes care of generating a token if needed and appending it to the layers.
Thank you very much Kelly!