<?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 render private feature layers with app auth in JS SDK in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-render-private-feature-layers-with-app-auth/m-p/150150#M13979</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;To authenticate against hosted layers, you would use oauth so the user can log in via their org account.&lt;/P&gt;&lt;P&gt;This sample shows this workflow used to view org items, but it's the same process for other items and services.&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/identity-oauth-basic/index.html" rel="nofollow noopener noreferrer" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/sample-code/identity-oauth-basic/index.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In your case, the important part would be setting up the OAuth information and register it with the identity manager., before loading the map. Once you do that, any requests that require authentication will go through the IdentityManager.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;var&lt;/SPAN&gt; info &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;new&lt;/SPAN&gt; &lt;SPAN class="token class-name"&gt;OAuthInfo&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
  &lt;SPAN class="comment token"&gt;// Swap this ID out with registered application ID&lt;/SPAN&gt;
  appId&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"YOURAPPID"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
  &lt;SPAN class="comment token"&gt;// Uncomment the next line and update if using your own portal&lt;/SPAN&gt;
  &lt;SPAN class="comment token"&gt;// portalUrl: "https://&amp;lt;host&amp;gt;:&amp;lt;port&amp;gt;/arcgis"&lt;/SPAN&gt;
  &lt;SPAN class="comment token"&gt;// Uncomment the next line to prevent the user's signed in state from being shared with other apps on the same domain with the same authNamespace value.&lt;/SPAN&gt;
  &lt;SPAN class="comment token"&gt;// authNamespace: "portal_oauth_inline",&lt;/SPAN&gt;
  popup&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;false&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;

esriId&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;registerOAuthInfos&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;info&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is a devlabs that also covers this topic.&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/labs/javascript/access-services-with-oauth-2/" rel="nofollow noopener noreferrer" target="_blank"&gt;https://developers.arcgis.com/labs/javascript/access-services-with-oauth-2/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You most likely want named user login&amp;nbsp;-&amp;nbsp;&lt;A href="https://developers.arcgis.com/documentation/core-concepts/security-and-authentication/signing-in-arcgis-online-users/" rel="nofollow noopener noreferrer" target="_blank"&gt;https://developers.arcgis.com/documentation/core-concepts/security-and-authentication/signing-in-arcgis-online-users/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is some doc on authentication patterns if you want to dig in for more details.&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/documentation/core-concepts/security-and-authentication/#authentication-patterns" rel="nofollow noopener noreferrer" target="_blank"&gt;https://developers.arcgis.com/documentation/core-concepts/security-and-authentication/#authentication-patterns&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you're interested to see how this works in an example application, you can look at the authentication code used in the &lt;A href="https://developers.arcgis.com/example-apps/nearby-javascript/" rel="nofollow noopener noreferrer" target="_blank"&gt;Nearby Places example JavaScript application&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/Esri/nearby-javascript/blob/master/src/data/oauth.ts" rel="nofollow noopener noreferrer" target="_blank"&gt;https://github.com/Esri/nearby-javascript/blob/master/src/data/oauth.ts&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 08:06:17 GMT</pubDate>
    <dc:creator>ReneRubalcava</dc:creator>
    <dc:date>2021-12-11T08:06:17Z</dc:date>
    <item>
      <title>How to render private feature layers with app auth in JS SDK</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-render-private-feature-layers-with-app-auth/m-p/150149#M13978</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Given that I am on 4.x of the JS SDK, I am struggling to find some example code of how I would authenticate requests made to the ArcGIS hosted layers that I have made private (but is shared within my organization).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am able to find several examples of enabling users to enter username and passwords, and the default behavior of a "private" feature layer is to pop a dialog box asking for user credentials - but this is not the desired workflow for my application.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've found mention of a few approaches, but have found next to nothing in code examples for the JS 4.x SDK in how to pull this off (I even have the IdentityManager documentation up, but haven't been able to find example code leveraging it with app auth). Here's what I've found, with the first being preferred:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- Prior to loading the private feature layers, the JS 4.x SDK is used to query the ArcGIS server, and thanks to the whitelisted referrers, it is given some sort of authorization token that allows future private feature layer requests to succeed.&lt;/P&gt;&lt;P&gt;- Prior to loading the private feature layers, the JS 4.x SDK queries our backend server that leverages .NET Core, which makes a request to the proxy application on the ArcGIS servers, and then returns some sort of authorization token to the client, which allows future private feature layer requests to succeed&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The second approach is obviously more difficult to implement, because not only will it likely be a longer request to complete as far as the client is concerned, the code that Esri provides does not work on .NET Core, so I'd be working off of some branched code that fellow Esri customers have provided on Github (not ideal).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Jun 2019 19:12:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-render-private-feature-layers-with-app-auth/m-p/150149#M13978</guid>
      <dc:creator>JeremyJarrell</dc:creator>
      <dc:date>2019-06-27T19:12:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to render private feature layers with app auth in JS SDK</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-render-private-feature-layers-with-app-auth/m-p/150150#M13979</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;To authenticate against hosted layers, you would use oauth so the user can log in via their org account.&lt;/P&gt;&lt;P&gt;This sample shows this workflow used to view org items, but it's the same process for other items and services.&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/identity-oauth-basic/index.html" rel="nofollow noopener noreferrer" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/sample-code/identity-oauth-basic/index.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In your case, the important part would be setting up the OAuth information and register it with the identity manager., before loading the map. Once you do that, any requests that require authentication will go through the IdentityManager.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;var&lt;/SPAN&gt; info &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;new&lt;/SPAN&gt; &lt;SPAN class="token class-name"&gt;OAuthInfo&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
  &lt;SPAN class="comment token"&gt;// Swap this ID out with registered application ID&lt;/SPAN&gt;
  appId&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"YOURAPPID"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
  &lt;SPAN class="comment token"&gt;// Uncomment the next line and update if using your own portal&lt;/SPAN&gt;
  &lt;SPAN class="comment token"&gt;// portalUrl: "https://&amp;lt;host&amp;gt;:&amp;lt;port&amp;gt;/arcgis"&lt;/SPAN&gt;
  &lt;SPAN class="comment token"&gt;// Uncomment the next line to prevent the user's signed in state from being shared with other apps on the same domain with the same authNamespace value.&lt;/SPAN&gt;
  &lt;SPAN class="comment token"&gt;// authNamespace: "portal_oauth_inline",&lt;/SPAN&gt;
  popup&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;false&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;

esriId&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;registerOAuthInfos&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;info&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is a devlabs that also covers this topic.&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/labs/javascript/access-services-with-oauth-2/" rel="nofollow noopener noreferrer" target="_blank"&gt;https://developers.arcgis.com/labs/javascript/access-services-with-oauth-2/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You most likely want named user login&amp;nbsp;-&amp;nbsp;&lt;A href="https://developers.arcgis.com/documentation/core-concepts/security-and-authentication/signing-in-arcgis-online-users/" rel="nofollow noopener noreferrer" target="_blank"&gt;https://developers.arcgis.com/documentation/core-concepts/security-and-authentication/signing-in-arcgis-online-users/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is some doc on authentication patterns if you want to dig in for more details.&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/documentation/core-concepts/security-and-authentication/#authentication-patterns" rel="nofollow noopener noreferrer" target="_blank"&gt;https://developers.arcgis.com/documentation/core-concepts/security-and-authentication/#authentication-patterns&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you're interested to see how this works in an example application, you can look at the authentication code used in the &lt;A href="https://developers.arcgis.com/example-apps/nearby-javascript/" rel="nofollow noopener noreferrer" target="_blank"&gt;Nearby Places example JavaScript application&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/Esri/nearby-javascript/blob/master/src/data/oauth.ts" rel="nofollow noopener noreferrer" target="_blank"&gt;https://github.com/Esri/nearby-javascript/blob/master/src/data/oauth.ts&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:06:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-render-private-feature-layers-with-app-auth/m-p/150150#M13979</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2021-12-11T08:06:17Z</dc:date>
    </item>
  </channel>
</rss>

