How to request a layer with a token in the Javascript API 4.x?

2744
7
04-06-2017 12:59 PM
CesarDuran
New Contributor II

Help please!

I am trying add a layer to a map using the JS API 4.x. This layer is a feature layer and it has a token to access to it.

In the Esri Javascipt I was add the layer just by specifying the token in the URL.

I am trying to do the same in 4.x however the app is always asking me for a user and password even if I already attached a valid token to the URL.

var myUrl = 'www.randomAddress.com';
var token = 'xioxioxioxioxioxioxioxioxio............'
var featureLayer = new FeatureLayer({
url: myURL + "?token=" + token
});

Is there a new way to do this in 4.x? 

I am attaching the code of the app and also an screenshot. Thank you very much!

0 Kudos
7 Replies
RobertScheitlin__GISP
MVP Emeritus

Cesar,

   The FeatureLayer Class has a token property.

https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#token 

var featureLayer = new FeatureLayer({
url: myURL
});

featureLayer.token = token;

EvelynHernandez
Occasional Contributor III

Nice!, i was wondering if that was added in the 3.20 version but no.

FeatureLayer | API Reference | ArcGIS API for JavaScript 3.20 

0 Kudos
FC_Basson
MVP Regular Contributor

You could probably just add the token parameter and value to the service URL e.g. [URL] + "&token=abc123"

CesarDuran
New Contributor II

I tried this before and I had the same problem.

Thank you!

0 Kudos
CesarDuran
New Contributor II

Hello Robert,

Thank you very much for your response. I actually tried this before and I just did it again however I have the same result.

Do you know if there is any limitations with the Esri server versions and Esri JS API 4.x?

I tried the same token with 3.x and works fine. I am attaching an image with the object in 4.x that shows that the token is there.

Thank you very much!

Token and URL JS Object

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Cesar,

   If that is not working then this sounds like a bug that needs to be reported to esri tech support. There is no version limitation that I am aware of.

CesarDuran
New Contributor II

Robert,

I was afraid of it. Thank you very much for your help!

Kind regards

0 Kudos