Access denied building web map

1019
5
03-21-2020 11:13 PM
JessieShapiro
New Contributor II

I'm building a web map with ArcGIS API for Javascript. I'm simply trying to add a feature layer to my web map but my login credentials keep getting denied. I know my password and username are correct. The feature layer I'm adding is not public, nor will I be able to make it public. Any idea why ArcGIS Online keeps denying me access when I try to open up the map in the web browser? 

Tags (1)
0 Kudos
5 Replies
Noah-Sager
Esri Regular Contributor

I would make sure that the app is hosted and not being run from file, and that the app has access to ArcGIS Online or ArcGIS Server (wherever the layer resides).

0 Kudos
JessieShapiro
New Contributor II

Thanks for the response. I'm writing my web map in an index.html file on my desktop using ArcGIS API for JavaScript in visual studio code. Could you explain how to save it to have access to ArcGIS Online?

The layer I'm using is on ArcGISOnline. When the layer is shared publicly I have no problem opening the web map and it doesn't ask for login credentials. But ultimately, I can't have this layer shared with the public.

Let me know if I should supply my code.

0 Kudos
Noah-Sager
Esri Regular Contributor

It's just a hunch, but if you know your credentials are correct, then I assume the issue is the app's ability to authenticate with ArcGIS Online. I would recommend testing the webmap's ID with one of our samples as a sanity check: ArcGIS API for JavaScript Sandbox 

Another option would be to go through this tutorial to make sure you have everything properly set-up: Display a web map | ArcGIS API for JavaScript 4.14 

And this development guide can help you get going as well: Quick Start | ArcGIS API for JavaScript 4.14 

If all else fails, please respond back here with a simplified reproducible test-app hosted on a place like codepen or jsbin and I can take a look.

0 Kudos
JessieShapiro
New Contributor II

Okay, I tested it in the Sandbox and my login credentials worked and I was able to open up the web map. I downloaded the code from the ArcGIS API for JavaScript Sandbox and saved it to my desktop. When I try to open the Html file from my desktop, my ArcGIS Online log in credentials are still being denied.

Here is the link to it in code pen. Although I was able to log in just fine on code pen too.

https://codepen.io/jshap925/pen/OJVBEwO 

Anything else I should try? Should I be saving my HTML file with the Javascript code somewhere else on my computer? Really really appreciate your help. 

0 Kudos
Noah-Sager
Esri Regular Contributor

No worries. Ok, that confirms what I thought, that this is not working because you are running the app from file locally and not on a server. The app needs to be hosted, either on a local webserver (e.g. IIS on Windows or Apache on MacOS), or in the cloud (e.g. codepen, or github.io). This is a general web development thing and not specific to working with the JS API. Here are some more resources to help you get going:

https://developers.arcgis.com/javascript/latest/guide/quick-start/

How do you set up a local testing server? - Learn web development | MDN 

IIS Web Server: (Internet Information Services) 

Set up localhost on macOS High Sierra (Apache, MySQL, and PHP 7) with SSL/HTTPS 

0 Kudos