Loading private feature layer into JavaScript map

245
2
02-18-2024 10:53 AM
JasonWood
New Contributor II

I have an ArcGIS Developer account, so I can access a private feature layer in my account by adding it to the scopes on my API Key page. 

But my client has an ArcGIS Online Account, and the documentation states "API keys cannot be used with ArcGIS Online accounts to access private hosted layer (items) and data services.", so if I understand correctly, that method will not work for them. (And I wouldn't want to use this method in production anyway, since the API Key would provide indefinite access to read the private layer)

I first attempted to solve this by getting an authentication token using my Client ID and Client Secret (server side), then passing this to my web application and assigning it to esriConfig.token (right below esriConfig.apiKey), but after removing the scope from the API Key settings, I am no longer able to load the private layer. Console message: "You do not have permissions to access this resource or perform this operation."

I know that the token has sufficient privileges because I can put the feature layer URL in a web browser and add "?token=[the token]" and it grants me access.

My questions:

1) How do I load a private feature layer using a token? Or is there a better way to load a private feature layer in an ArcGIS Online account (when the user of the web application is not an ArcGIS user)?

2) How can I limit the privileges of the token so it is read only and only for that one feature layer?

0 Kudos
2 Replies
AddisonShaw
New Contributor III

You'll have to have your client provide you with OAuth credentials to access their layer. 

0 Kudos
LaurenBoyd
Esri Contributor

Hi @JasonWood -

If the user of the web application is not an ArcGIS user and does not have an ArcGIS named user account, then the data needs to be publicly shared. This is outlined in the Master Agreement in section 2.6 Value-Added Applications: https://www.esri.com/content/dam/esrisites/en-us/media/legal/ma-translations/english.pdf 

API keys are an exception because they are used with Developer accounts (not an ArcGIS Online account with named user licenses).

Lauren
0 Kudos