Solved! Go to Solution.
Send your URLs to the proxy.ashx and the authentication will be handled for you.
<serverUrl url="http://sampleserver2.arcgisonline.com/arcgis/rest/services/" matchAll="true" token="jijdfihjd023r33yr837r37"></serverUrl>
esri.config.defaults.io.proxyUrl = "your_location_to_proxy_page/proxy.ashx"; esri.config.defaults.io.alwaysUseProxy = "true";