Catching IdentityManager prompt when loading ArcGIS Online webmap

5902
7
Jump to solution
05-15-2014 08:54 AM
KenDoman
Occasional Contributor II
We have an application that loads a publicly available webmap from ArcGIS Online. Every once in a while, the Identity Manager pops up and challenges us to access the application. When this happens, usually there's something wrong with our account. But that's beside the point.

Because the application won't be used to load private data, or data behind token security, I need to intercept the 'dialog-create' event from the IdentityManager, and automatically close the dialog to trigger the error loading event. How do I access the IdentityManager when I call arcgisUtils.createMap?
0 Kudos
1 Solution

Accepted Solutions
KenDoman
Occasional Contributor II

What I ended up doing was to test for the presence of ESRI's Identity Manager Dialog using dojo/query, If the dialog was present, I hid the dialog and presented my own error message. Below I've added some code I used to search for this.

var scanForLogin;

arcgisUtils.createMap(agolId, mapDivId, { mapOptions: mapOptions })

    .then(onSuccess, onFailure);

// check if a login is required.

require(["dojo/query", "dijit/registry"], function (dojoQuery, registry) {

    var loginChecks = 0;

    scanForLogin = window.setInterval(function () {

        // testing access to sign in node

        var signInNode = dojoQuery(".esriSignInDialog"),

            promptDialog;

        // if there is a signin node

        if (signInNode.length) {

            promptDialog = registry.byNode(signInNode[0]);

            promptDialog.hide(); // hide the prompt dialog

            onFailure({message: "Map failed to load properly"});

        } else if (this.loginChecks > 4) {

            // stops checking after five times (over 3 seconds).

            window.clearInterval(this.scanForLogin);

        }

        loginChecks++;

    }, 600);

});

function onSuccess (response) {

    // stop checking for login

    window.clearInterval(scanForLogin);

    ...

}

function onFailure (err) {

    // stop checking for login

    window.clearInterval(scanForLogin);

    alert(err.message || err.Message);

}

View solution in original post

0 Kudos
7 Replies
DasaPaddock
Esri Regular Contributor
Can you try switching to the compact build? This doesn't include the IdentityManager by default.

See: https://developers.arcgis.com/javascript/jshelp/inside_compactbuild.html
0 Kudos
KenDoman
Occasional Contributor II
Thanks, that helped. It introduced another issue somewhere else, but I'll save that for another forum post.
0 Kudos
KenDoman
Occasional Contributor II
Loading the compact build introduced some other changes to the application that we didn't want. Are there any other ways to either:
1. Stop the IdentityManager or
2. Find an attach point for the IdentifyManager, either in arcgis.utils where I'm calling createMap, or wherever, to attach an event when it shows.

Thanks,
0 Kudos
DasaPaddock
Esri Regular Contributor
You could use the JavaScript Web Optimizer to create a custom build that does not include the IndentityManager.
0 Kudos
KenDoman
Occasional Contributor II

What I ended up doing was to test for the presence of ESRI's Identity Manager Dialog using dojo/query, If the dialog was present, I hid the dialog and presented my own error message. Below I've added some code I used to search for this.

var scanForLogin;

arcgisUtils.createMap(agolId, mapDivId, { mapOptions: mapOptions })

    .then(onSuccess, onFailure);

// check if a login is required.

require(["dojo/query", "dijit/registry"], function (dojoQuery, registry) {

    var loginChecks = 0;

    scanForLogin = window.setInterval(function () {

        // testing access to sign in node

        var signInNode = dojoQuery(".esriSignInDialog"),

            promptDialog;

        // if there is a signin node

        if (signInNode.length) {

            promptDialog = registry.byNode(signInNode[0]);

            promptDialog.hide(); // hide the prompt dialog

            onFailure({message: "Map failed to load properly"});

        } else if (this.loginChecks > 4) {

            // stops checking after five times (over 3 seconds).

            window.clearInterval(this.scanForLogin);

        }

        loginChecks++;

    }, 600);

});

function onSuccess (response) {

    // stop checking for login

    window.clearInterval(scanForLogin);

    ...

}

function onFailure (err) {

    // stop checking for login

    window.clearInterval(scanForLogin);

    alert(err.message || err.Message);

}

0 Kudos
DavidElies
New Contributor III

Does anyone, (especially at ESRI), have a solution to this that doesn't require using a completely different build of the API or having an interval that hides the popup after the fact?  Is there really no way to stop it?  If our credentials expire or the layer cannot load for some other reason, we certainly don't want our users to get an ugly, clear popup that has absolutely no meaning to them (the users certainly don't have access to the username and password, heck, I don't even have access to them), we just want it to fail gracefully so we can show the user that the layer has failed and log it so someone who does have access to these things can fix it.  It seems silly to show this login box by default, since the consumer of the layer (ostensibly me) and the consumer of the website (our clients) are completely different and showing this failure to properly authenticate on our part to our customers is very unprofessional.  Is there a way to fix this?

0 Kudos
DasaPaddock
Esri Regular Contributor

Another option is to set the global reference to null in your first require callback using:

esri.id = null;
0 Kudos