Select to view content in your preferred language

Programing arcgis login online js 4.15

1529
6
06-21-2020 07:57 AM
GenasysEsri
Emerging Contributor

Hello everyone,

I just tried load a customfeatrue layer from my arcgis online account. I did it whitout problems

However every time and open my script there is an esri-identity-form wich ask for user and password (image I added). So, I would like load my personal layers from arcgis online whitout show or view this form, I mean try other way to loading and authentication or just authentication in background process.

Could anyone show me a easy example??

Thanks!!!

Tags (1)
0 Kudos
6 Replies
VictorTey
Esri Contributor

Hi, several thoughts come to mind. Possible options are,

Using the esri proxy, add your login cred to the proxy.

GitHub - Esri/resource-proxy: Proxy files for DotNet, Java and PHP. 

Second option would be to manage the token yourself. E.g 

  • Get token from rest endpoint
  • Every url request you make, append &token=xxxxx to the url.
0 Kudos
GenasysEsri
Emerging Contributor

Hello Victor,

Thanks for your answer.

I have never manage a resource-proxy, the link you attached talks about DotNet, Java and PHP but I am using Javascript. So, I don't understand very well all what it talks about.

Like you see I not have a hight programing level....I was looking for something I can understand, some code or example like:

"This code could help you: you user go here, your password in there..."

Thanks anyway, I keep going study about your answer for finding what I am loking for.

0 Kudos
VictorTey
Esri Contributor

Hi sure. note that the proxy is just another option, without knowing the full context of what you are trying to do

I can expand a bit more on the proxy option however it will still require you to read some of the documentation to see if it suits your requirement.

A proxy essentially acts as a gateway. What that means is that instead of accessing your service url directly like below which requires authentication:

http://services.arcgisonline.com/ArcGIS/rest/services/?f=pjson

if you access it via the proxy, it will manage the token for you. (username and password are stored in the proxy config)

http://[yourmachine]/DotNet/proxy.ashx?http://services.arcgisonline.com/ArcGIS/rest/services/?f=pjson

I am going to assume you have access to a web server like microsoft windows IIS. Because it is IIS, look in the DotNet part of the resource-proxy.

resource-proxy/DotNet at master · Esri/resource-proxy · GitHub 

Link above provides detail description on how to deploy. Basically it is just copy/paste file, do the config and change your access URL.

Proxy configuration:

resource-proxy/README.md at master · Esri/resource-proxy · GitHub 

Note the username and password option

0 Kudos
GenasysEsri
Emerging Contributor

Thanks a lot.


For understanding what I am doing:

I use this code for loading a featureLayer from my Arcgis Online Account:

CustomArcgisLayer = new FeatureLayer({

            url: my service url (https://services6.arcgis.com/ ......),
});

Every time I start my html or application there appear a credential dialog, so, I did this for fill this dialog.
Basically I fill it using javascript

var form_esri_dialog=document.getElementsByClassName("esri-identity-modal esri-identity-modal--open")[0];

if(typeof form_esri_dialog!="undefined"){

            var user= Array.from(document.getElementsByClassName("esri-identity-                form")  [0].querySelectorAll('input[type="text"]'));

              var password=Array.from(document.getElementsByClassName("esri-

              identity- form") [0].querySelectorAll('input[type="password"]'));

               user[0].value="xxxx";
               password[0].value="xxxxx";

               var submit_form= Array.from(document.getElementsByClassName("esri-identity-

               form")[0].querySelectorAll('input[type="submit"]'));

               submit_form[0].click();

I would like not doing this ...I would like do this in a background process or automatically

I will look all the information you gave me,

Very thanks again

0 Kudos
VictorTey
Esri Contributor

So the 2 options I have provide, either one will work.

1 - using the resource-proxy will require 0 coding, you just need to use service url via the proxy as demostrated above.

2 - you can get the token from Generate Token—ArcGIS REST API: Users, groups, and content | ArcGIS for Developers. you need to code this part (Many ways to do this, esri also have a class you can use request | ArcGIS API for JavaScript 4.15 ) 

Once you have the token, append it to your url.

CustomArcgisLayer = new FeatureLayer({

            url: my service url (https://url.to.your.service/..../whatever&token=fdksfdsfdsa),
});

GenasysEsri
Emerging Contributor

Very very thanks.

The first option I don't know how could do it ..it is like chinese lenguage for my...I just have a standart arcgis online account..I thought it will be more easy

For the second option the same problem, my url has token and for creating a permanent token (I don't know if your option goes for these way) the example doesn't give to me how write it in javascript

Generate Token

Example1:

https://www.arcgis.com/sharing/rest/generateToken

username=jsmith33

password=myPassword

referer=https://www.arcgis.com

I think it will be in request, but where and how....I don`t see this in request information:

// request GeoJson data from USGS remote server

var url = "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_hour.geojson";

esriRequest(url, {

   responseType: "json" })

.then(function(response){

// The requested data

var geoJson = response.data; });

So, How could mix both of them??

I don't want to tire you with my questions.


I will continue using the way that works for me now and I understand

I am very grateful for your attention and responses.
You would understand if you didn't answer me, I'm asking a lot from you

0 Kudos