Last active
April 26, 2019 21:27
-
-
Save nommuna2/4caf4114fa44d197e0b3207c7682cd66 to your computer and use it in GitHub Desktop.
(ArcGIS API for JavaScript) Sample of getting user items and accessing secured layers without user authentication.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(["esri/map", | |
"esri/arcgis/Portal", | |
"esri/urlUtils", | |
"esri/request", | |
"esri/config", | |
"dojo/domReady!" | |
], function (Map, arcgisPortal,urlUtils, Request, Config) { | |
//Push the server to the cors array to avoid CORS related errors. | |
Config.defaults.io.corsEnabledServers.push("FQDN of server"); | |
var map = new Map("map", { | |
center: [-118, 34.5], | |
zoom: 8, | |
basemap: "topo" | |
}); | |
//Add a proxy rule, to send requests through the proxy | |
urlUtils.addProxyRule({ | |
urlPrefix: "FQDN of the web server which the proxy is on", | |
proxyUrl: "https://FQDN/DotNet/proxy.ashx" | |
}); | |
var urls = [ | |
"https://FQDN/portal/sharing/rest/content/users/admin", //See what files are associated with a certain user from portal. | |
"https://FQDN/server/rest/services/Hosted/Cites/FeatureServer" //Access a secured layer from portal. | |
]; | |
//Send a request using the request module | |
urls.forEach((element) =>{ | |
var request = new Request({ | |
url: element, | |
content: {f:"pjson"}, | |
handleAs: "json" | |
}); | |
request.then((response) => { console.log(response);}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a sample using the proxy to access items and secured layers from a portal. The use of a proxy allows you to store credentials in the proxy config so that the end user will not have to log in.
Additional information to be aware of: