Select to view content in your preferred language

Secured MapImageLayer - unable to retrieve layer legend

605
2
Jump to solution
05-01-2023 02:46 AM
patryks
New Contributor III

In my application I already have an api token (retrieved it using rest call). Now I want to use this token to load layers.

When I load FeatureLayer everything works just fine (FeatureLayer has apiKey parameter documented). Both layer and legend loads without problems.

When i try to load MapImageLayer (this layer does not have apiKey), the layer itself load just fine but the legend call does not use provided token and causes to login form pop up. After cancelling login form I have following warning in console:

patryks_0-1682934177112.png

How to properly provide apiKey to MapImageLayer? I already tried

  • appending token parameter to url
  • adding apiKey in esriConfig

without success.

0 Kudos
1 Solution

Accepted Solutions
Noah-Sager
Esri Regular Contributor

Hi @patryks, thank you for posting your question here. I think there is some confusion over the term API key. 

An API key is used primarily for location services. It can also access private items in a portal. 

https://developers.arcgis.com/documentation/mapping-apis-and-services/security/api-keys/

We also discuss best practices for accessing secure or private content with the ArcGIS Maps SDK for JavaScript.

https://developers.arcgis.com/javascript/latest/secure-resources/

However, the cause of the issue you're seeing could be because a FeatureLayer can be published to a portal, but because a MapImageLayer is server-side, it must be published to Enterprise, and then it can be shared to a portal. So that may be why MapImageLayer and Sublayer do not have an apiKey property, but FeatureLayer does. I would recommend looking at the guide page for tips on working with a secured MapImageLayer.

View solution in original post

2 Replies
Noah-Sager
Esri Regular Contributor

Hi @patryks, thank you for posting your question here. I think there is some confusion over the term API key. 

An API key is used primarily for location services. It can also access private items in a portal. 

https://developers.arcgis.com/documentation/mapping-apis-and-services/security/api-keys/

We also discuss best practices for accessing secure or private content with the ArcGIS Maps SDK for JavaScript.

https://developers.arcgis.com/javascript/latest/secure-resources/

However, the cause of the issue you're seeing could be because a FeatureLayer can be published to a portal, but because a MapImageLayer is server-side, it must be published to Enterprise, and then it can be shared to a portal. So that may be why MapImageLayer and Sublayer do not have an apiKey property, but FeatureLayer does. I would recommend looking at the guide page for tips on working with a secured MapImageLayer.

patryks
New Contributor III

It seems that I misunderstood the concept. According to link you provided 

https://developers.arcgis.com/javascript/latest/secure-resources/

I need an "application login" to standalone arcgis server. I retrieve such token using 

https://developers.arcgis.com/rest/users-groups-and-items/generate-token.htm

then I registered this token using IdentityManager.registerToken method and it is working. Thank you!

0 Kudos