<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to Access Secured ArcGIS Server Map Service? in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-access-secured-arcgis-server-map-service/m-p/1287169#M81098</link>
    <description>&lt;P&gt;has anyone found a solution to this issue?&lt;/P&gt;</description>
    <pubDate>Tue, 09 May 2023 09:46:37 GMT</pubDate>
    <dc:creator>RiddhiM</dc:creator>
    <dc:date>2023-05-09T09:46:37Z</dc:date>
    <item>
      <title>How to Access Secured ArcGIS Server Map Service?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-access-secured-arcgis-server-map-service/m-p/1042775#M72320</link>
      <description>&lt;P&gt;Hello Everyone,&lt;/P&gt;&lt;P&gt;Thanks for reading my post.&lt;/P&gt;&lt;P&gt;We're using JS API to access the secured service and we're expecting it wouldn't ask for the user credentials as we're passing Token, but it's not working as expected and asking for credentials.&lt;/P&gt;&lt;P&gt;Following is the code:-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset="utf-8" /&amp;gt;
    &amp;lt;meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" /&amp;gt;
    &amp;lt;title&amp;gt;&amp;lt;/title&amp;gt;
    &amp;lt;style&amp;gt;
        html,
        body,
        #viewDiv {
            padding: 0;
            margin: 0;
            height: 100%;
            width: 100%;
        }
    &amp;lt;/style&amp;gt;
    &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/4.18/esri/themes/light/main.css"&amp;gt;
    &amp;lt;script src="https://js.arcgis.com/4.18/"&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;script&amp;gt;
        require(["esri/config", "esri/Map", "esri/views/MapView", "esri/layers/FeatureLayer"], function (esriConfig, Map, MapView, FeatureLayer) {

            esriConfig.apiKey = "AAPK9c1060b46848481f85233a3e7-Bf1Yng_hEZz";

            const map = new Map({
                basemap: "arcgis-topographic" // Basemap layer service
            });

            const view = new MapView({
                map: map,
                center: [115.860299, -31.954594], // Longitude, latitude
                zoom: 13, // Zoom level
                container: "viewDiv" // Div element
            });

            const featureLayerUrl = "https://services.slip.wa.gov.au/arcgis/rest/services/Landgate_v2_Subscription_Services/Cadastral/MapServer/41";
            //const featureLayerUrl = "https://token.slip.wa.gov.au/arcgis/rest/services/Landgate_v2_Subscription_Services/Cadastral/MapServer/41";

            var layer = new FeatureLayer({
                url: featureLayerUrl,                
                customParameters: {
                    "token": "nXKRnEHxOLrfCyV_209zi9ht45yzP-IIrvjZzsrI."//Get the token from https://token.slip.wa.gov.au/arcgis/tokens/
                }
            });

            map.add(layer);
        });
    &amp;lt;/script&amp;gt;    
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;div id="viewDiv"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Apr 2021 01:36:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-access-secured-arcgis-server-map-service/m-p/1042775#M72320</guid>
      <dc:creator>ZohaibUddinKhan</dc:creator>
      <dc:date>2021-04-02T01:36:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to Access Secured ArcGIS Server Map Service?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-access-secured-arcgis-server-map-service/m-p/1042885#M72325</link>
      <description>&lt;P&gt;You cannot reuse the same token like that. You have to &lt;A href="https://developers.arcgis.com/rest/users-groups-and-items/generate-token.htm" target="_self"&gt;generate a token&lt;/A&gt; when the app loads and gets user credentials. You could also consider &lt;A href="https://developers.arcgis.com/javascript/latest/secure-resources/#standalone-arcgis-server" target="_self"&gt;application authentication&lt;/A&gt; if you don't want to get credentials from each user.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Apr 2021 14:23:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-access-secured-arcgis-server-map-service/m-p/1042885#M72325</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-04-01T14:23:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to Access Secured ArcGIS Server Map Service?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-access-secured-arcgis-server-map-service/m-p/1043309#M72333</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/191789"&gt;@BlakeTerhune&lt;/a&gt;&amp;nbsp;for the reply.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Is there any other way apart from&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/secure-resources/#standalone-arcgis-server" target="_self" rel="nofollow noopener noreferrer"&gt;application authentication&lt;/A&gt;&amp;nbsp;if I don't want to get credentials from each users?&lt;/LI&gt;&lt;LI&gt;I changed my code and now generating the Token in the code like below and CORS is the challenge I'm facing now. Any suggestion?:-&lt;/LI&gt;&lt;/OL&gt;&lt;LI-CODE lang="javascript"&gt;&amp;lt;script&amp;gt;
        function getToken() {

            var settings = {
                "url": "https://token.slip.wa.gov.au/arcgis/tokens/generateToken",
                "method": "POST",
                "timeout": 0,
                "headers": {
                    "Content-Type": "application/x-www-form-urlencoded"
                },
                "data": {
                    "username": "username@domain.com",
                    "password": "678965",
                    "client": "referer",
                    "ip": "",
                    "referer": "https://www.domain.com/",
                    "expiration": "60",
                    "f": "json"
                },
                async: false
            };

            return $.ajax(settings).done().responseText;

        }
        console.log('1');
        var result = getToken();
        var token1 = $.parseJSON(result).token;

        require(["esri/config", "esri/Map", "esri/views/MapView", "esri/layers/FeatureLayer"], function (esriConfig, Map, MapView, FeatureLayer) {

            esriConfig.apiKey = "AAPK9c1060b46848481f85233a3e-_hEZz";

            const map = new Map({
                basemap: "arcgis-topographic" // Basemap layer service
            });

            const view = new MapView({
                map: map,
                center: [115.860299, -31.954594], // Longitude, latitude
                zoom: 13, // Zoom level
                container: "viewDiv" // Div element
            });

            const featureLayerUrl = "https://services.slip.wa.gov.au/arcgis/rest/services/Landgate_v2_Subscription_Services/Cadastral/MapServer/41";
            //const featureLayerUrl = "https://token.slip.wa.gov.au/arcgis/rest/services/Landgate_v2_Subscription_Services/Cadastral/MapServer/41";

            var layer = new FeatureLayer({
                url: featureLayerUrl,
                customParameters: {
                    "token": token1
                }
            });

            map.add(layer);

        });
    &amp;lt;/script&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;This is the Cors challenge:-&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Esri-Token-Cors.PNG" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/9972i8492B7905FE75CE8/image-size/large?v=v2&amp;amp;px=999" role="button" title="Esri-Token-Cors.PNG" alt="Esri-Token-Cors.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thanks for your time.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Apr 2021 07:20:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-access-secured-arcgis-server-map-service/m-p/1043309#M72333</guid>
      <dc:creator>ZohaibUddinKhan</dc:creator>
      <dc:date>2021-04-02T07:20:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to Access Secured ArcGIS Server Map Service?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-access-secured-arcgis-server-map-service/m-p/1148791#M76505</link>
      <description>&lt;P&gt;Any luck getting this to work?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Feb 2022 21:16:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-access-secured-arcgis-server-map-service/m-p/1148791#M76505</guid>
      <dc:creator>MarkEastwood</dc:creator>
      <dc:date>2022-02-28T21:16:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to Access Secured ArcGIS Server Map Service?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-access-secured-arcgis-server-map-service/m-p/1148817#M76506</link>
      <description>&lt;P&gt;CORS is always a challenge. Have a look at &lt;A href="https://developers.arcgis.com/javascript/latest/cors/" target="_self"&gt;the documentation&lt;/A&gt; to see if you can identify the solution for your particular setup. The easiest (but not always most reasonable) solution is to run your app from the same server as your services.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Feb 2022 21:45:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-access-secured-arcgis-server-map-service/m-p/1148817#M76506</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2022-02-28T21:45:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to Access Secured ArcGIS Server Map Service?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-access-secured-arcgis-server-map-service/m-p/1287169#M81098</link>
      <description>&lt;P&gt;has anyone found a solution to this issue?&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 09:46:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-access-secured-arcgis-server-map-service/m-p/1287169#M81098</guid>
      <dc:creator>RiddhiM</dc:creator>
      <dc:date>2023-05-09T09:46:37Z</dc:date>
    </item>
  </channel>
</rss>

