Oauth2 Login Programmatically with no login prompts

01-20-2022 02:47 PM
New Contributor


Could someone please provide an example to programmatically create an Oauth2 flow so that I am able to login using an ESRI user account and prevent the ESRI login prompts.  I have started to use the Oauth2 rest Authorize service to get a token but keep getting a cors error.  I verified that for some reason the ESRI service is not sending back the CORS headers.  I can however call the Oauth2/ rest token endpoint with CORS headers and a token no problem but I cant get a token for an ESRI user without a code from the Authorize endpoint.  If someone has an example or might know why the CORS  headers are missing from the Authorize call it would be appreciated.  I also dont want to put a proxy in if I dont have to.Thanks!

Tags (2)
0 Kudos
1 Reply
New Contributor III


I know this doesn't directly answer your question regarding how to implement Oauth2 (am not familiar enough with it to speak on the subject). But in regards to bypassing log in prompts for secured services you might look into storing credentials within a registered service (if that is something you can do in your situation). Then use the rest end point for the registered service in your JavaScript code. You would be using ESRI as a proxy more or less, and you can still manage the sharing access of the registered service through your portal or AGOL. The coolest part is that you can even manage the traffic for the registered service, so that it will only allow requests from specified URLs.

Connect to secure services—Portal for ArcGIS | Documentation for ArcGIS Enterprise

How To: Add secure ArcGIS Server services as items in ArcGIS Online (esri.com)

0 Kudos