<?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: Having trouble with oauth2.0 app authentication in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/having-trouble-with-oauth2-0-app-authentication/m-p/1342939#M82600</link>
    <description>&lt;P&gt;OK I took a look and followed the documentation here.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://developers.arcgis.com/documentation/mapping-apis-and-services/security/app-credential-authentication/" target="_blank" rel="noopener"&gt;https://developers.arcgis.com/documentation/mapping-apis-and-services/security/app-credential-authentication/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I did an&amp;nbsp;&lt;SPAN&gt;npm install @esri/arcgis-rest-auth.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Which installed the node package in directory within my project and has ApplicationSession.js.&lt;/P&gt;&lt;P&gt;In my code, I have it imported here:&lt;/P&gt;&lt;PRE&gt; require([
        "esri/Map",
        "esri/views/MapView",
        "esri/layers/FeatureLayer",
        "esri/identity/OAuthInfo",
        "esri/identity/IdentityManager",
        "esri/arcgis-rest-auth/ApplicationSession",&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm still unsure why this isn't being recognized.&lt;/P&gt;</description>
    <pubDate>Fri, 27 Oct 2023 20:47:09 GMT</pubDate>
    <dc:creator>GIS412</dc:creator>
    <dc:date>2023-10-27T20:47:09Z</dc:date>
    <item>
      <title>Having trouble with oauth2.0 app authentication</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/having-trouble-with-oauth2-0-app-authentication/m-p/1342880#M82595</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm new to the ArcGIS API for Javascript. I'm currently working on a project&amp;nbsp; that requires me to use a rest endpoint on our enterprise portal. This will be public facing, so there is no need to have people accessing this page to ask for login information. The user should be able to click the link to the webpage and it should open up.&lt;/P&gt;&lt;P&gt;I've read up on the documentation here:&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/documentation/mapping-apis-and-services/security/app-credential-authentication/" target="_blank"&gt;https://developers.arcgis.com/documentation/mapping-apis-and-services/security/app-credential-authentication/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Going with OAuth2.0 with app credential authentication. I've created my clientid and client secret. I've created my small project. Here's the code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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;Public Map with App Credentials Authentication&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.28/esri/themes/light/main.css"
    /&amp;gt;
    &amp;lt;script src="https://js.arcgis.com/4.28/"&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;script&amp;gt;
      require([
        "esri/Map",
        "esri/views/MapView",
        "esri/layers/FeatureLayer",
        "esri/identity/OAuthInfo",
        "esri/identity/IdentityManager",
        "esri/arcgis-rest-auth/ApplicationSession",
      ], (Map, MapView, FeatureLayer, OAuthInfo, IdentityManager, ApplicationSession) =&amp;gt; {
        const session = new ApplicationSession({
          clientId: 'my_client_id',
          clientSecret: 'my_client_secret',
          grant_type:'client_credentials',
          duration: 60
        });
        session.getToken("https://www.arcgis.com/sharing/rest/oauth2/token")
          .then(function(response) {
            console.log('this is the response ', response);
          }).catch(function(error) {
            // request failed, handle errors
            console.log('error ', error);
          });

        // App Credentials configuration
        const oauthInfo = new OAuthInfo({
          appId: "my_client_id",
          popup: false, // No popup for user login
          portalUrl: "my_enterprise_portal",
        });

        IdentityManager.registerOAuthInfos([oauthInfo]);

        // Initialize the map and view
        const map = new Map({
          basemap: "topo-vector",
        });

        const view = new MapView({
          container: "viewDiv",
          map: map,
          zoom: 12,
          center: [-122.64, 47.577],
        });

        // Load the feature layer after signing in with App Credentials
        IdentityManager.checkSignInStatus(oauthInfo.portalUrl).then(() =&amp;gt; {
          // Create a feature layer from the REST endpoint
          const featureLayer = new FeatureLayer({
            url: "my_rest_endpoint",
          });

          map.layers.add(featureLayer); // Add the feature layer to the map
        });
      });
    &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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Because of security, I've chosen to withhold my clientid, client secret, enterprise portal url, and rest endpoint.&lt;/P&gt;&lt;P&gt;When I run this code and check the console via developer tools, I'm getting these errors.&lt;/P&gt;&lt;P&gt;Failed to load resource: the server responded with a status of 404 ()&lt;BR /&gt;(index):31.&amp;nbsp;ApplicationSession.js:1 Failed to load resource: the server&amp;nbsp;&lt;/P&gt;&lt;P&gt;Error: scriptError: &lt;A href="https://js.arcgis.com/4.28/esri/arcgis-rest-auth/ApplicationSession.js" target="_blank" rel="noopener"&gt;https://js.arcgis.com/4.28/esri/arcgis-rest-auth/ApplicationSession.js&lt;/A&gt;&lt;BR /&gt;at h ((index):6)&lt;BR /&gt;at HTMLScriptElement.&amp;lt;anonymous&amp;gt; ((index):30)&lt;BR /&gt;(anonymous) @ (index):31&lt;/P&gt;&lt;P&gt;This leads me to believe there is a problem with ApplicationSession.js? I've double checked my node directory and see it exists. It is in this directory (which is in a subdirectory of my main project):&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="applicationsession.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/84317i72F7A3182A94B29F/image-size/large?v=v2&amp;amp;px=999" role="button" title="applicationsession.png" alt="applicationsession.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Can anyone point me in the right direction? I've been lost on this for the past few days and am not sure how to move forward from here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2023 20:39:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/having-trouble-with-oauth2-0-app-authentication/m-p/1342880#M82595</guid>
      <dc:creator>GIS412</dc:creator>
      <dc:date>2023-10-27T20:39:23Z</dc:date>
    </item>
    <item>
      <title>Re: Having trouble with oauth2.0 app authentication</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/having-trouble-with-oauth2-0-app-authentication/m-p/1342909#M82597</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/708891"&gt;@GIS412&lt;/a&gt;&amp;nbsp;-&lt;/P&gt;&lt;P&gt;The ArcGIS Maps SDK for JavaScript doesn't have an&amp;nbsp;ApplicationSession class and I couldn't find that anywhere other than in the "Upgrade from v3 to v4" page in the ArcGIS REST JS documentation:&amp;nbsp;&lt;A href="https://developers.arcgis.com/arcgis-rest-js/release-notes/upgrade-v3-v4/#improving-authentication" target="_blank"&gt;https://developers.arcgis.com/arcgis-rest-js/release-notes/upgrade-v3-v4/#improving-authentication&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The error shows that a request is attempting to be sent to&amp;nbsp;&lt;A href="https://js.arcgis.com/4.28/esri/arcgis-rest-auth/ApplicationSession.js" target="_blank" rel="noopener nofollow noreferrer"&gt;https://js.arcgis.com/4.28/esri/arcgis-rest-auth/ApplicationSession.js&lt;/A&gt;, which doesn't exist so that seems to be the issue. This is not one of our modules in the JS Maps SDK.&lt;/P&gt;&lt;P&gt;Maybe you need to add some code to import that class from the ArcGIS REST JS library:&amp;nbsp;&lt;A href="https://developers.arcgis.com/arcgis-rest-js/install/#node-js" target="_blank"&gt;https://developers.arcgis.com/arcgis-rest-js/install/#node-js&lt;/A&gt;? Or use &lt;A href="https://developers.arcgis.com/arcgis-rest-js/api-reference/arcgis-rest-request/ApplicationCredentialsManager/" target="_self"&gt;ApplicatonCredentialsManager&lt;/A&gt; instead?&lt;/P&gt;&lt;P&gt;Hope this helps!&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2023 19:42:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/having-trouble-with-oauth2-0-app-authentication/m-p/1342909#M82597</guid>
      <dc:creator>LaurenBoyd</dc:creator>
      <dc:date>2023-10-27T19:42:21Z</dc:date>
    </item>
    <item>
      <title>Re: Having trouble with oauth2.0 app authentication</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/having-trouble-with-oauth2-0-app-authentication/m-p/1342923#M82599</link>
      <description>&lt;P&gt;Will look at this. Thanks!!!!&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2023 20:17:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/having-trouble-with-oauth2-0-app-authentication/m-p/1342923#M82599</guid>
      <dc:creator>GIS412</dc:creator>
      <dc:date>2023-10-27T20:17:44Z</dc:date>
    </item>
    <item>
      <title>Re: Having trouble with oauth2.0 app authentication</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/having-trouble-with-oauth2-0-app-authentication/m-p/1342939#M82600</link>
      <description>&lt;P&gt;OK I took a look and followed the documentation here.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://developers.arcgis.com/documentation/mapping-apis-and-services/security/app-credential-authentication/" target="_blank" rel="noopener"&gt;https://developers.arcgis.com/documentation/mapping-apis-and-services/security/app-credential-authentication/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I did an&amp;nbsp;&lt;SPAN&gt;npm install @esri/arcgis-rest-auth.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Which installed the node package in directory within my project and has ApplicationSession.js.&lt;/P&gt;&lt;P&gt;In my code, I have it imported here:&lt;/P&gt;&lt;PRE&gt; require([
        "esri/Map",
        "esri/views/MapView",
        "esri/layers/FeatureLayer",
        "esri/identity/OAuthInfo",
        "esri/identity/IdentityManager",
        "esri/arcgis-rest-auth/ApplicationSession",&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm still unsure why this isn't being recognized.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2023 20:47:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/having-trouble-with-oauth2-0-app-authentication/m-p/1342939#M82600</guid>
      <dc:creator>GIS412</dc:creator>
      <dc:date>2023-10-27T20:47:09Z</dc:date>
    </item>
  </channel>
</rss>

