Jeff,Here is the sample code to do log in behind the scene, I have copy pasted the code from my app(written in version 2.8) so you might have to do little modification:<script type="text/javascript">
dojo.require("dojo.parser");
dojo.require("esri.IdentityManager");
var cred = "esri_jsapi_id_manager_data";
var shortLivedTokenValidity=60;
function init() {
var idBase = new esri.IdentityManagerBase();
esri.config.defaults.io.proxyUrl = "proxy.ashx";
var serverInfo = {
"server": "http://myserver:8399",
"tokenServiceUrl": "http://myserver/arcgis/tokens",
"currentVersion": 10.4
};
var def = idBase.generateToken(serverInfo, { "username": "rahul", "password": "rahul" });
def.addCallback(function (tokenInfo) {
var idBase = new esri.IdentityManagerBase();
//Short lived token is valid for 60 mins by defult
idBase.tokenValidity =shortLivedTokenValidity=60;
var serverInfo = {
"server": "http://myserver:8399",
"tokenServiceUrl": "http://csslsystem-254:8399/arcgis/tokens",
"currentVersion": 10.04
};
esri.id.registerServers([serverInfo]);
//get token creation time in epoch
var creationTime = (new Date).getTime();
//calculate the token expiration based on short lived token validity
var expirationTime = creationTime + (shortLivedTokenValidity * 60000);
//create array of secured services
var securedServices = [];
for (var services in this.configData.mapService) {
securedServices.push(this.configData.mapService[services]);
}
var idString = dojo.toJson({ "serverInfos": [serverInfo],
"credentials": [{
"userId": rahul,
"server": "http://myserver:8399",
"token": tokenInfo.token,
"expires": expirationTime,
"ssl": false,
"creationTime": creationTime,
"resources": securedServices
}]
});
// store it client side
if (_supports_local_storage()) {
// use local storage
window.localStorage.setItem(this._jsAPIIDManagerData, idString);
} else {
// use a cookie
dojo.cookie(this._jsAPIIDManagerData, idString, { expires: 1 });
}
this._loadCredentials();
});
}
function _supports_local_storage() {
try {
return "localStorage" in window && window["localStorage"] !== null;
} catch (e) {
return false;
}
}
function _loadCredentials() {
var idJson, idObject;
if (this._supports_local_storage()) {
// read from local storage
idJson = window.localStorage.getItem(this._jsAPIIDManagerData);
} else {
// read from a cookie
idJson = dojo.cookie(this._jsAPIIDManagerData);
}
if (idJson && idJson != "null" && idJson.length > 4) {
idObject = dojo.fromJson(idJson);
esri.id.initialize(idObject);
}
}
dojo.addOnLoad(init);
</script>
I hope this helps you.