How to get UserID of user that is currently signed in to application?

08-25-2015 04:29 PM
New Contributor III

In a widget we need to be able to grab the UserID of the user currently logged in to the app (e.g. assuming they have signed in via AGOL or Portal), and then pass this userID as a string input parameter to another web service. Is this possible? Any ideas on how we can access current userID?

We have previously been using Geocortex Essentials and Workflow Designer, and there was a "GetCurrentUser" activity that made this very easy to do, and I was hoping there might be something like this that can be used in a Widget?

I saw that the Javascript API has a method called "Credential"

Credential | API Reference | ArcGIS API for JavaScript  that includes UserID, but I am not sure I understand  where we would call this or, or if we can even access the credentials from within a Widget once the user has already authenticated?

Thanks for any feedback/ideas.

For reference, I have already looked at following threads relating to securing applications to try to better understand how authentication works for Web Apps made with WAB Dev Edition (though am still digesting the material to make sense...):

Authentication through ArcGIS Online for customized Web Apps

Second login prompts while authenticating arcgis online with oAuth

0 Kudos
6 Replies
New Contributor III

Hi Pascual,

You can use the singleton IdentityManager for this.

Add IdentityManager to your widget and access credentials through this:










You probably will want to add some checks to see if user is signed in as well.

Read more: IdentityManager | API Reference | ArcGIS API for JavaScript

New Contributor III

Herdis Gudbrandsdottir, thank you for pointing us in right direction! We will test this out.

I see that this sample code will be useful to see in action: OAuth Basic | ArcGIS API for JavaScript

For checking to see if the user is signed in or not, it looks like we would use the checksigninstatus method, correct?

Also, do you know if there might be any limitations on this approach if users are authenticating via Portal for Server configured to use Integrated Windows Authentication (IWA)? That is, does the Javascript IdentityManager support IWA?  I found the following description of IdentityManger in context of ArcGIS RunTime SDK for .NET that suggests it should work:

Listing 13

IdentityManager supports accessing resources on systems secured using ArcGIS tokens, OAuth, network authentication (e.g., Integrated Windows Authentication [IWA]), and client certificates. This includes secure resources hosted by ArcGIS for Server, Portal for ArcGIS, and ArcGIS Online. A set of classes is derived from Esri.ArcGISRuntime.Security.Credential to reference different types of security protocols. These include ArcGISTokenCredential, OAuthTokenCredential, ArcGISNetworkCredential, and CertificateCredential. During a challenge, use CredentialRequestInfo.AuthenicationType to determine the type of credential to create or return.

(Source: Integrate GIS Functionality into Windows Apps with ArcGIS Runtime SDK for .NET | ArcUser )

but I could not tell if this description was specific only to the the support provided by the .NET runtime?

0 Kudos
New Contributor III

I would take a look at esri.arcgis.Portal and getPortalUser() for cases where user is signed in using IWA:

Portal (legacy) | API Reference | ArcGIS API for JavaScript

And yes checkSignInStatus(resUrl) would be the correct way to get hold of the credential object

New Contributor III

Thank you Herdis.

0 Kudos
Occasional Contributor III

I think you can use this way(IdentityManager.credentials[0].userId) even though your portal is authenticated by IWA.

New Contributor III

Thank you Junshan.

0 Kudos