Registering Token Method not working

10-28-2013 01:04 PM
New Contributor III
I am trying to write my own widget to log-in to ArcGIS Online, and i am able to get the token back but i am never able to register the token with the identity manager so that  i can pull down all of the users' content to view. when i try to query the user i get back no results, when i look at the network activity in chrome i see that the search url does not have the token in it, so i tried manually copying that search link into a new tab and manually putting the token in the request URL and i was about to get my results back, but when i try to put the token string in the query parameters which does include the token string in the request URL it tells me that i have an invalid token...but if i right click the URL with the "invalid token" and open it in a new tab it baffled and the methods on the documentation dont work....does anyone else have any experience or any idea on what to do?

  <script type="text/javascript">
      var path_location = location.pathname.replace(/\/[^/]+$/, '');
      var dojoConfig = {
        parseOnLoad: true,
        async : true
  <script type="text/javascript" src="">
   var userLogin;

       var _username;
       var _password;
       var tokenStr;
       var expireStr;

       userLogin = function()

         _username = document.getElementById("user").value;
         _password = document.getElementById("pass").value;

        var request =  esri.request({
                url: "",
                content: {
                        request: "generateToken",
                        username: _username,
                        password: _password,
                        referer : "",
                        f: "json"
                handleAs: "json",
                load: tokenObtained,
                error: tokenRequestFailed
               }, {usePost : true});

       function tokenObtained(response) 

               tokenStr = response.token;
               expireStr = response.expires;

               var token = {
                "server": "",
                "userId": _username,
                "token": tokenStr,
                "ssl": true,
                "expires": expireStr

             {server:  "",
                  userId:  _username,
                  token:   tokenStr,
                  expires: expireStr,
                  ssl:     true
               //console.log("token: ",token);
                //console.log("token: ",tokenStr);

       function tokenRequestFailed(response) 

               console.log("in TORF", response);

             function displayItems() {

           function queryPortal(portalUser) {
             var portal = new Portal.Portal("");
             //dojo.connect(portal, 'onLoad', loadPortal);

             //var user = portal.getPortalUser();
             //See list of valid item types here:
             //See search reference here:
             //function loadPortal() {
              var queryParams = {
               //token: tokenStr,
                q:          "owner:" + portalUser, //+" AND (type: Feature Service OR type: Map Service)" ,
                sortField:  "numViews",
                sortOrder:  "desc",
                num:        20

           function createGallery(items) {
             var htmlFragment = "";
             arrayUtils.forEach(items.results, function(item) {
               htmlFragment += (
                 "<div class=\"esri-item-container\">" +
                     item.thumbnailUrl ?
                     "<div class=\"esri-image\" style=\"background-image:url(" + item.thumbnailUrl + ");\"></div>" :
                     "<div class=\"esri-image esri-null-image\">Thumbnail not available</div>"
                   ) +
                     item.title ?
                     "<div class=\"esri-title\">" + (item.title || "") + "</div>" :
                     "<div class=\"esri-title esri-null-title\">Title not available</div>"
                   ) +
             dom.byId("itemGallery").innerHTML = htmlFragment;


  <h2>Sign-in to ArcGIS Online</h2>
   Username: <input name="username" id="user" size="27" type="text" />
   <br />
   Password: <input name="password" id="pass" size="27" type="password" />
   <br />
   <input type="button" name="action_login" value="Sign-in" onclick="userLogin()" />
0 Kudos
5 Replies
Frequent Contributor
Do you have your proxy page all set up?  I don't see any reference to it.  I believe it's a requirement for anything related to the IdentityManager.
0 Kudos
New Contributor III
Do you have your proxy page all set up?  I don't see any reference to it.  I believe it's a requirement for anything related to the IdentityManager.

I havent been using one, no. I have been able to register the a token using the appid and app secret using almost the same methodology before, and i just verified today that i didnt need the proxy for that.

Also i dont believe this sample has a poxy either.
0 Kudos
Occasional Contributor

Did this issue ever get resolved?  I'd like to do a similar thing (get a token out-of-band, and populate IdentityManager with it).  I'm seeing the same result, where I can call registerToken(), and it seems to work, but interactions with the Portal objects never append the registered token.

0 Kudos
Occasional Contributor

FWIW, I was able to solve my problem and get the RegisterToken method to work.  My issue was the referer parameter that was used when requesting a token.  Make sure that maps back to the host that is serving the page.

In reference to the code above, I believe you'll need to call signIn on the Portal object before it will start appending tokens on requests.  The IdentityManager and Portal objects seem to work together to pull that off:

new arcgisPortal.Portal("").signIn().then(function (portalUser) { //use portal here }

New Contributor

I am getting token when I pass client_id and client_secret.

I have passed the token generated to the but when I try to invoke webmap from my server it is again propmting the default login dialog. Can anyone know the resolution for this issue without using proxy installation ?

0 Kudos