Where does the parameter "portalUser" come from?

2393
20
Jump to solution
03-21-2017 10:43 AM
JoseSanchez
Occasional Contributor III

Hello everyone,

I do not understand very well the notation for this function:    function (portalUser){

The parameter "portalUser" where is it populated and declared?

Is there any online converted that changes from AMD to other structure easier to read?

This function is used in this sample: https://developers.arcgis.com/javascript/3/jssamples/portal_oauth_inline.html

Thanks

function displayItems(){
     
new arcgisPortal.Portal(info.portalUrl).signIn().then(
       
function (portalUser){
          console
.log("Signed in to the portal: ", portalUser);

          domAttr
.set("userId", "innerHTML", portalUser.fullName);
          domStyle
.set("anonymousPanel", "display", "none");
          domStyle
.set("personalizedPanel", "display", "block");

          queryPortal
(portalUser);
       
}
     
).otherwise(
       
function (error){
          console
.log("Error occurred while signing in: ", error);
       
}
     
);

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Jose,

   It looks fine to me except that the signIn method returns a potalUser as the deferred result:

var portal = new arcgisPortal.Portal('http://[my organitation].maps.arcgis.com');
portal.signIn().then(function (loggedInUser){‍‍‍
  console.log("Signed in to the portal: ", loggedInUser‍‍‍);
  console.log(loggedInUser‍‍‍.fullName);
  var myArray = null;
  var myArray = loggedInUser‍‍‍.getGroups;
});

Are you adding a break point inside the then portion?

View solution in original post

20 Replies
RobertScheitlin__GISP
MVP Emeritus

Jose,

   "portalUser" is the promise result of the new arcgisPortal.Portal(info.portalUrl).signIn() function.

signIn():

Prompts the user using the IdentityManager and returns a deferred that, when resolved, returns the PortalUser for the input credentials.

https://developers.arcgis.com/javascript/3/jsapi/portal-amd.html#signin 

JoseSanchez
Occasional Contributor III

Thanks Robert,

In this sample, how do I instantiate "portalUser"  if I already log in into the web application. ?

I want to add this code to check the groups from an user that already logged in.

require([
 
"dojo/_base/array", ...
], function(array, ... ) {
  portalUser
.getFolders().then(function(folders){
    array
.forEach(folders,function(folder){
     
if(folder.title === 'javascript'){
        folderid
= folder.id;
     
}
   
});
 
});
 
...
});

http://ncsiapps.ncsi.gov.om/arcgis_js_api/sdk/jsapi/portaluser-amd.html

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jose,

  You can get the portal user from the portal object using the getPortalUser() method:

https://developers.arcgis.com/javascript/3/jsapi/portal-amd.html#getportaluser 

JoseSanchez
Occasional Contributor III

Thanks again,

what I do not understand is how the object  "portal" gets instantiated? or how can declare an object myPortal = initialize it with "portal".

 

Fired when the portal has loaded. Once the portal has loaded the properties and methods of the Portal class are available. (Added at v3.6)
Sample:
portal.on("load", function(){
  console.log(portal.allSSL);
});
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

The Portal class uses the IdentityManager to signin a user so if the user is already authenticated when you use Portal signIn I would not expect it to re-prompt for login so you should be good just calling portal signin.

0 Kudos
JoseSanchez
Occasional Contributor III

What I don't understand is how the object "portal" gets populated. This is my function

require([
 
"esri/arcgis/Portal", ...

], function(arcgisPortal, ... ) {

//Retrieves user information.

checkUser: function() {

portal = new arcgisPortal ???????????   How is this object instantiated   ??????

console.log(portal.allSSL);

console.log(portal.signIn());

console.log(portal.getPortalUser());

},

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jose,

   If you are saying that your app is already logged in then that means the IdentityManger was used for some secured Portal resource. So just use:

var portal = new arcgisPortal.Portal('http://blahblah.maps.arcgis.com');
0 Kudos
JoseSanchez
Occasional Contributor III

Thank you Robert.

0 Kudos
JoseSanchez
Occasional Contributor III

One last questions,

how do I instantiate PortalGroup  ?

var portalgroup = new  ????

or do I need to run a query on Portal to get all groups?

Thanks

0 Kudos