Using identity manager, how to i get access to the token to use later

1797
5
11-04-2011 12:52 PM
JeffPace
MVP Alum
I have an app that uses secure services.  I use the identity manager to login and it works great.

Part of the site builds a toc that uses the rest legends via separate calls (i loop through all the this.map.getLayer(layerId).url and make an dojo.xhrGet to the /MapServer/legend?f=json

but i need to append the token on it, which i never see.  How do I get access to it?

If i used esri.request instead of dojo.xhrGet would it put the token on?
0 Kudos
5 Replies
KellyHutchins
Esri Frequent Contributor
Identity Manager is a singleton class that is automatically instantiated into esri.id when you load the module into your application. When you sign in using the identity manager the credentials are stored in esri.id.credentials. So if you need access to the token you can do something like this:

console.log(esri.id.credentials[0].token);
0 Kudos
JeffPace
MVP Alum
Kelly,
Thank you so much, this has worked perfectly for me.

I load my layers, and if it hits a secure layer it prompts excellently.  My only problem is i do something after the layers load, and since it is all asynchronous, the delay of logging in is making me miss my event.

I do it onLayerAdd, it doesn't seem that this event is being fired after a layer is loaded that includes a challenge from the identity manager.

Is there an onSuccessLogin type event that i can listen for to trigger my refresh (its for a TOC legend).
0 Kudos
KellyHutchins
Esri Frequent Contributor
There isn't - but we are looking at adding events to the IdentityManager.

"Is there an onSuccessLogin type event that i can listen for to trigger my refresh"
0 Kudos
JeffPace
MVP Alum
There isn't - but we are looking at adding events to the IdentityManager.

"Is there an onSuccessLogin type event that i can listen for to trigger my refresh"


Ok thanks for the info, that would be great.  Basically I loop through a list of layers and use the map.addLayer method.  If one is secure, it prompts, but the others continue to load.  Its seems like, however, that after my credentials pass the onLayerAdd event has already passed.
0 Kudos
KellyHutchins
Esri Frequent Contributor
What about if you add the layers to the map using map.addLayers([array of layers to add]). Then you could listen for the 'onLayersAddResult' event which fires after all the layers have been added.
0 Kudos