Login ArcGIS online in background using Identity Manager

Discussion created by tonylife on Apr 24, 2013
I am not able to do background login and get item from ArcGIS online somehow.

What I am doing is, I manually generateToken using IdentityManagerBase and then manipulate cookie information with tokeninfo.

Then I use with cookie to re-hydrate the state of identity manager. But login window would still pop up to ask for credential.

However If I simply use popup window to login first time and let IdentityManager to handle cookie, it does work. I don't get pop up anymore.

Here is the IdentityManager generated cookie

Here is the cookie I manipulated

I compared both cookies, and it seems that only difference is token.

Here is the code for generateToken. Am I missing something?
var idBase = new esri.IdentityManagerBase();
    var serverInfo = {
        "server": "",
        "tokenServiceUrl": ""
    var def = idBase.generateToken(serverInfo, { "username": "MYUSERNAME*", "password": "MYPASSWORD", "client": "referer", "referer": "http://MYIP:MYPORT/index.html" });

BTW, I am running app in localhost right now.
Any thought would be appreciated!