Registering Token Method not working

Discussion created by scottgrace on Oct 28, 2013
Latest reply on Jan 26, 2016 by brassier
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()" />