Retrieve logged in user + role from AGOL

423
9
05-07-2018 02:38 AM
BrettKruger
New Contributor II

HI Guys

Hope you are well.

I am wondering of someone could assist me or point me into a direction, perhaps someone has done this before but I have not gotten much info on it just yet.

I have a 3rd party system I wrote using .net. This system is has a link in the organizational online portal to it and on the feature class as well. Although I need to grab the user that has logged in via their online portal in .NET.

Any ideas how to access the token from the server side as the user lands in the 3rd party system? Using vb.net in the backend.

Also by grabbing the token, I see in JS it gives the user + role but like I said I need to grab it on the system load and store it perhaps somewhere?

Any ideas would be helpful

Thanks

Brett

0 Kudos
9 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Brett,

   Here is how I pass JS Variable from JS to .Net code behind:

create a hidden field variable in the vb.net html code:

<asp:HiddenField ID="jsVariable" runat="server" />


and in javascript you can assign your js value to the hidden variable using

<script type="text/javascript">
  var myfunction = function () {
    var jsVariable = document.getElementById('jsVariable');
    jsVariable.value = 'javascript var';
  }
</script>‍‍‍‍‍‍


then you can read the hidden variable field from the code behind using

dim variable as String = jsVariable.Value;
BrettKruger
New Contributor II

HI Robert

Yet again thanks for your reply and input!

Will go test this and come back but it sounds really good, I knew it had to be something simple and accessible.

Brett

0 Kudos
BrettKruger
New Contributor II

Hi Robert

I do understand the code given above, to pass a JS variable over and store it in a hidden field to retrieve from the server side.

My question is however, if a user is logged in on the AGOL and uses the link provided in there to my system, how would I grab the person who is logged in username and the role assigned to him in his organization?

Thanks

Brett

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Brett,

   So let me see if I am following you... You have a JS app that the user clicks on a link and it takes then to an VB.Net app and you want to send the AGOL user info to that VB.Net app? If that is the case then url parameters in the link is the best solution.

0 Kudos
BrettKruger
New Contributor II

Hi Robert

Not exactly.

So basically, a client of mine has their own ArcGIS online portal at ****.maps.arcgis.com.

I have added a link there to another system that I wrote using vb.net that I host on my own server.

The problem I am facing is that users in this organization has different roles, now depending on these roles coming from ArcGIS online they get to access certain parts in my system.

So what I need to do is, as soon as they use the link provided in their online portal I need to somehow grab the user that is logged in as well as the role assigned to him.

It comes down to linking my system which has nothing to do with ArcGIS online, to be able to get users + roles when landing on my home page.

My thoughts was that as soon as someone logs into their ArcGIS Online, it has to store the token somehow in the browser or somewhere for external systems to be able to get that type of info?

I hope this makes sense

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Brett,

  Hmm... The fact that you do not have control of the code that the link exists in makes this complicated... Your right there has to be some record of the user info but that info would be encrypted and controlled by the originating Portal and I don't know of a way to gain access to it from just a link in the Portal.

0 Kudos
BrettKruger
New Contributor II

Hi Robert

The only possible way I thought to overcome this is maybe do it in a widget.

Basically I want to have a user click a feature on the map and then get the user that is logged in and its role assigned?

I have been playing around the identityManager but have not had much luck, is this the right route or is it possible to get the info through a widget when the user clicks the map?

thanks again for all your help and responses.

Brett

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Brett,

  Getting the logged in user is pretty simple in a WAB widget. See this thread:

https://community.esri.com/thread/185734-using-portalutils-to-get-current-logged-user-wont-work-for-... 

BrettKruger
New Contributor II

Thanks for this, will start exploring this option, as this would be my other option on how to integrate the 2 systems and know which user/role is currently on the map.

As always thanks a lot for the information.

0 Kudos