<?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 Correct pattern for checking if a logged in user has access to a Portal item? in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/correct-pattern-for-checking-if-a-logged-in-user/m-p/1047931#M72581</link>
    <description>&lt;P&gt;In my JS 4.x application I am using IdentityManager and OAuth (via appid/secret) to have users login to my Portal (10.8.1). &amp;nbsp;There are plenty of examples showing how to do this. &amp;nbsp;What I’m having trouble figuring out is how to then determine if a user has access to the resource (a Portal layer) that my site wants to load. &amp;nbsp;If they DO have access, I then want to load the layer onto the map, but if they don’t, then the site might do something else (like load a different layer, or change a div to say they don’t have access). So far all I’ve figured out how to do is just login (Authentication), not check if they have access to what I want them to (authorization). &amp;nbsp;I tried changing the sharing of the actual registered app item in Portal, but all Portal users can still successfully login using that app’s registered info, not just the ones I shared it with. &amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyone have suggestions for a working pattern here?&lt;/P&gt;</description>
    <pubDate>Fri, 16 Apr 2021 00:53:38 GMT</pubDate>
    <dc:creator>Jay_Gregory</dc:creator>
    <dc:date>2021-04-16T00:53:38Z</dc:date>
    <item>
      <title>Correct pattern for checking if a logged in user has access to a Portal item?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/correct-pattern-for-checking-if-a-logged-in-user/m-p/1047931#M72581</link>
      <description>&lt;P&gt;In my JS 4.x application I am using IdentityManager and OAuth (via appid/secret) to have users login to my Portal (10.8.1). &amp;nbsp;There are plenty of examples showing how to do this. &amp;nbsp;What I’m having trouble figuring out is how to then determine if a user has access to the resource (a Portal layer) that my site wants to load. &amp;nbsp;If they DO have access, I then want to load the layer onto the map, but if they don’t, then the site might do something else (like load a different layer, or change a div to say they don’t have access). So far all I’ve figured out how to do is just login (Authentication), not check if they have access to what I want them to (authorization). &amp;nbsp;I tried changing the sharing of the actual registered app item in Portal, but all Portal users can still successfully login using that app’s registered info, not just the ones I shared it with. &amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyone have suggestions for a working pattern here?&lt;/P&gt;</description>
      <pubDate>Fri, 16 Apr 2021 00:53:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/correct-pattern-for-checking-if-a-logged-in-user/m-p/1047931#M72581</guid>
      <dc:creator>Jay_Gregory</dc:creator>
      <dc:date>2021-04-16T00:53:38Z</dc:date>
    </item>
    <item>
      <title>Re: Correct pattern for checking if a logged in user has access to a Portal item?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/correct-pattern-for-checking-if-a-logged-in-user/m-p/1047934#M72582</link>
      <description>&lt;P&gt;Here's some code from a VueJS app where I think we do what you are trying to do.&amp;nbsp; In the code below, we use our registered app id to get the user to log in but then also load, using PortalItem, the registered app using it's item ID.&amp;nbsp; On the ArcGIS Enterprise side, the registered app is shared with a group the user is a member of so the user should only be able to load the app if they are a member of that group.&amp;nbsp; I suppose the registered app could be replaced with any item shared with the appropriate group the user needs to be a member of but this approach seems to keep it nice and tidy and self-contained.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps!&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import vuetify from './plugins/vuetify'
import IdentityManager from '@arcgis/core/identity/IdentityManager'
import OAuthInfo from '@arcgis/core/identity/OAuthInfo'
import Portal from '@arcgis/core/portal/Portal'
import PortalItem from '@arcgis/core/portal/PortalItem'
import '@arcgis/core/assets/esri/themes/light/main.css'

Vue.config.productionTip = false

const registerdAppId = '123456789'
const portalUrl = 'https://my.arcgisenterprise/portal'
const registeredAppItemId = '987654321'

const highlightText = function (words, query) {
  if (!words) return ''

  return words.replace(new RegExp(query, 'gi'), match =&amp;gt; {
    return '&amp;lt;span class=\'highlight\'&amp;gt;' + match + '&amp;lt;/span&amp;gt;'
  })
}

const info = new OAuthInfo({
  appId: registerdAppId,
  portalUrl: portalUrl,
  popup: false
})

const esriId = IdentityManager
esriId.registerOAuthInfos([info])

const portal = new Portal({
  url: portalUrl,
  authMode: 'immediate'
})
portal
  .load()
  .then(function (results) {
    const appItem = new PortalItem({
      id: registeredAppItemId,
      portal: portal
    })
    appItem
      .load()
      .then(function (results) {
        Vue.filter('highlight', highlightText)
        new Vue({
          router,
          store,
          vuetify,
          render: h =&amp;gt; h(App)
        }).$mount('#app')
      }, function () {
        alert('You are not authorized for this application')
      })
  })

window.addEventListener('beforeunload', (event) =&amp;gt; {
  esriId.destroyCredentials()
})&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 16 Apr 2021 01:18:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/correct-pattern-for-checking-if-a-logged-in-user/m-p/1047934#M72582</guid>
      <dc:creator>Jade_Freeman</dc:creator>
      <dc:date>2021-04-16T01:18:57Z</dc:date>
    </item>
  </channel>
</rss>

