<?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 How to log into Portal with JSAPI 4?? in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-log-into-portal-with-jsapi-4/m-p/1004564#M70903</link>
    <description>&lt;P&gt;I'm trying to access my Portal items with JSAPI 4.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code works below, however when logging in I get a different login screen that what I am use to getting. This is preventing me to login with my Okta account. (see image)&lt;/P&gt;&lt;P&gt;&amp;nbsp;I registered the App in Portal and copied over the AppID. (see image)&lt;/P&gt;&lt;P&gt;We are using Auth2.0&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AdamArcichowski_0-1606277566418.png" style="width: 627px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/937i8CB42E6459B0C452/image-dimensions/627x296?v=v2" width="627" height="296" role="button" title="AdamArcichowski_0-1606277566418.png" alt="AdamArcichowski_0-1606277566418.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AdamArcichowski_1-1606277740488.png" style="width: 742px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/938iDCD26A1F299F5029/image-dimensions/742x538?v=v2" width="742" height="538" role="button" title="AdamArcichowski_1-1606277740488.png" alt="AdamArcichowski_1-1606277740488.png" /&gt;&lt;/span&gt;&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 http-equiv="Content-Type" content="text/html; 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;Query Portal Items&amp;lt;/title&amp;gt;

  &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/next/esri/css/main.css"&amp;gt;

  &amp;lt;script src="https://js.arcgis.com/next/"&amp;gt;&amp;lt;/script&amp;gt;
  &amp;lt;style&amp;gt;
    html,
    body {
      width: 100%;
      height: 100%;
      margin: 0px;
      padding: 0px;
    }

    .esri-item-gallery .esri-item-container {
      float: left;
      text-align: center;
      padding: 10px;
      width: 204px;
    }

    .esri-item-gallery .esri-image {
      width: 200px;
      height: 133px;
      border: 2px solid gray;
      border-radius: 5px;
    }

    .esri-item-gallery .esri-null-image {
      line-height: 133px;
      text-align: center;
      color: #999999;
    }

    .esri-item-gallery .esri-title {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .esri-item-gallery .esri-null-title {
      color: #999999;
    }

    .action {
      color: blue;
      cursor: pointer;
      text-decoration: underline;
    }

  &amp;lt;/style&amp;gt;
  &amp;lt;script&amp;gt;
    require([
      "esri/portal/Portal",
      "esri/identity/OAuthInfo",
      "esri/identity/IdentityManager",
      "esri/portal/PortalQueryParams",
      "dojo/dom-style",
      "dojo/dom-attr",
      "dojo/dom",
      "dojo/on",
      "dojo/_base/array",
      "dojo/domReady!"
    ], function (Portal, OAuthInfo, esriId, PortalQueryParams,
      domStyle, domAttr, dom, on, arrayUtils) {
      var info = new OAuthInfo({
        // Swap this ID out with registered application ID
        appId: "XXXXXXXXXXX",
        // Uncomment the next line and update if using your own portal
         portalUrl: "https://XXXXXXX.XXXX.com/portal",
        // 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.
        // authNamespace: "portal_oauth_inline",
        popup: false
      });
      esriId.registerOAuthInfos([info]);

      esriId.checkSignInStatus(info.portalUrl + "/sharing").then(
        function () {
          displayItems();
        }
      ).catch(
        function () {
          // Anonymous view
          domStyle.set("anonymousPanel", "display", "block");
          domStyle.set("personalizedPanel", "display", "none");
        }
      );

      on(dom.byId("sign-in"), "click", function () {
        // user will be redirected to OAuth Sign In page
        esriId.getCredential(info.portalUrl + "/sharing");
      });

      on(dom.byId("sign-out"), "click", function () {
        esriId.destroyCredentials();
        window.location.reload();
      });

      function displayItems() {

        var portal = new Portal();
        // Setting authMode to immediate signs the user in once loaded
        portal.authMode = "immediate";
        // Once loaded, user is signed in
        portal.load().then(function () {
          // Create query parameters for the portal search
          var queryParams = new PortalQueryParams({
            query: "owner:" + portal.user.username,
            sortField: "numViews",
            sortOrder: "desc",
            num: 20
          });

          domAttr.set("userId", "innerHTML", portal.user.username);
          domStyle.set("anonymousPanel", "display", "none");
          domStyle.set("personalizedPanel", "display", "block");

          // Query the items based on the queryParams created from portal above
          portal.queryItems(queryParams).then(createGallery);
        });
      }

      function createGallery(items) {
        var htmlFragment = "";

        arrayUtils.forEach(items.results, function (item) {
          htmlFragment += (
            "&amp;lt;div class=\"esri-item-container\"&amp;gt;" +
            (item.thumbnailUrl ?
              "&amp;lt;div class=\"esri-image\" style=\"background-image:url(" +
              item.thumbnailUrl + ");\"&amp;gt;&amp;lt;/div&amp;gt;" :
              "&amp;lt;div class=\"esri-image esri-null-image\"&amp;gt;Thumbnail not available&amp;lt;/div&amp;gt;") +
            (item.title ?
              "&amp;lt;div class=\"esri-title\"&amp;gt;" + (item.title || "") +
              "&amp;lt;/div&amp;gt;" :
              "&amp;lt;div class=\"esri-title esri-null-title\"&amp;gt;Title not available&amp;lt;/div&amp;gt;") +
            "&amp;lt;/div&amp;gt;");
        });
        dom.byId("itemGallery").innerHTML = htmlFragment;
      }
    });

  &amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
  &amp;lt;div id="anonymousPanel" style="display: none; padding: 5px; text-align: center;"&amp;gt;
    &amp;lt;span id="sign-in" class="action"&amp;gt;Sign In&amp;lt;/span&amp;gt; and view your ArcGIS Online items.
  &amp;lt;/div&amp;gt;

  &amp;lt;div id="personalizedPanel" style="display: none; padding: 5px; text-align: center;"&amp;gt;
    Welcome &amp;lt;span id="userId" style="font-weight: bold;"&amp;gt;&amp;lt;/span&amp;gt; &amp;amp;nbsp;-&amp;amp;nbsp;
    &amp;lt;span id="sign-out" class="action"&amp;gt;Sign Out&amp;lt;/span&amp;gt;
  &amp;lt;/div&amp;gt;

  &amp;lt;div id="itemGallery" class="esri-item-gallery" style="width: 100%;"&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>Wed, 25 Nov 2020 04:18:39 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2020-11-25T04:18:39Z</dc:date>
    <item>
      <title>How to log into Portal with JSAPI 4??</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-log-into-portal-with-jsapi-4/m-p/1004564#M70903</link>
      <description>&lt;P&gt;I'm trying to access my Portal items with JSAPI 4.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code works below, however when logging in I get a different login screen that what I am use to getting. This is preventing me to login with my Okta account. (see image)&lt;/P&gt;&lt;P&gt;&amp;nbsp;I registered the App in Portal and copied over the AppID. (see image)&lt;/P&gt;&lt;P&gt;We are using Auth2.0&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AdamArcichowski_0-1606277566418.png" style="width: 627px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/937i8CB42E6459B0C452/image-dimensions/627x296?v=v2" width="627" height="296" role="button" title="AdamArcichowski_0-1606277566418.png" alt="AdamArcichowski_0-1606277566418.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AdamArcichowski_1-1606277740488.png" style="width: 742px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/938iDCD26A1F299F5029/image-dimensions/742x538?v=v2" width="742" height="538" role="button" title="AdamArcichowski_1-1606277740488.png" alt="AdamArcichowski_1-1606277740488.png" /&gt;&lt;/span&gt;&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 http-equiv="Content-Type" content="text/html; 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;Query Portal Items&amp;lt;/title&amp;gt;

  &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/next/esri/css/main.css"&amp;gt;

  &amp;lt;script src="https://js.arcgis.com/next/"&amp;gt;&amp;lt;/script&amp;gt;
  &amp;lt;style&amp;gt;
    html,
    body {
      width: 100%;
      height: 100%;
      margin: 0px;
      padding: 0px;
    }

    .esri-item-gallery .esri-item-container {
      float: left;
      text-align: center;
      padding: 10px;
      width: 204px;
    }

    .esri-item-gallery .esri-image {
      width: 200px;
      height: 133px;
      border: 2px solid gray;
      border-radius: 5px;
    }

    .esri-item-gallery .esri-null-image {
      line-height: 133px;
      text-align: center;
      color: #999999;
    }

    .esri-item-gallery .esri-title {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .esri-item-gallery .esri-null-title {
      color: #999999;
    }

    .action {
      color: blue;
      cursor: pointer;
      text-decoration: underline;
    }

  &amp;lt;/style&amp;gt;
  &amp;lt;script&amp;gt;
    require([
      "esri/portal/Portal",
      "esri/identity/OAuthInfo",
      "esri/identity/IdentityManager",
      "esri/portal/PortalQueryParams",
      "dojo/dom-style",
      "dojo/dom-attr",
      "dojo/dom",
      "dojo/on",
      "dojo/_base/array",
      "dojo/domReady!"
    ], function (Portal, OAuthInfo, esriId, PortalQueryParams,
      domStyle, domAttr, dom, on, arrayUtils) {
      var info = new OAuthInfo({
        // Swap this ID out with registered application ID
        appId: "XXXXXXXXXXX",
        // Uncomment the next line and update if using your own portal
         portalUrl: "https://XXXXXXX.XXXX.com/portal",
        // 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.
        // authNamespace: "portal_oauth_inline",
        popup: false
      });
      esriId.registerOAuthInfos([info]);

      esriId.checkSignInStatus(info.portalUrl + "/sharing").then(
        function () {
          displayItems();
        }
      ).catch(
        function () {
          // Anonymous view
          domStyle.set("anonymousPanel", "display", "block");
          domStyle.set("personalizedPanel", "display", "none");
        }
      );

      on(dom.byId("sign-in"), "click", function () {
        // user will be redirected to OAuth Sign In page
        esriId.getCredential(info.portalUrl + "/sharing");
      });

      on(dom.byId("sign-out"), "click", function () {
        esriId.destroyCredentials();
        window.location.reload();
      });

      function displayItems() {

        var portal = new Portal();
        // Setting authMode to immediate signs the user in once loaded
        portal.authMode = "immediate";
        // Once loaded, user is signed in
        portal.load().then(function () {
          // Create query parameters for the portal search
          var queryParams = new PortalQueryParams({
            query: "owner:" + portal.user.username,
            sortField: "numViews",
            sortOrder: "desc",
            num: 20
          });

          domAttr.set("userId", "innerHTML", portal.user.username);
          domStyle.set("anonymousPanel", "display", "none");
          domStyle.set("personalizedPanel", "display", "block");

          // Query the items based on the queryParams created from portal above
          portal.queryItems(queryParams).then(createGallery);
        });
      }

      function createGallery(items) {
        var htmlFragment = "";

        arrayUtils.forEach(items.results, function (item) {
          htmlFragment += (
            "&amp;lt;div class=\"esri-item-container\"&amp;gt;" +
            (item.thumbnailUrl ?
              "&amp;lt;div class=\"esri-image\" style=\"background-image:url(" +
              item.thumbnailUrl + ");\"&amp;gt;&amp;lt;/div&amp;gt;" :
              "&amp;lt;div class=\"esri-image esri-null-image\"&amp;gt;Thumbnail not available&amp;lt;/div&amp;gt;") +
            (item.title ?
              "&amp;lt;div class=\"esri-title\"&amp;gt;" + (item.title || "") +
              "&amp;lt;/div&amp;gt;" :
              "&amp;lt;div class=\"esri-title esri-null-title\"&amp;gt;Title not available&amp;lt;/div&amp;gt;") +
            "&amp;lt;/div&amp;gt;");
        });
        dom.byId("itemGallery").innerHTML = htmlFragment;
      }
    });

  &amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
  &amp;lt;div id="anonymousPanel" style="display: none; padding: 5px; text-align: center;"&amp;gt;
    &amp;lt;span id="sign-in" class="action"&amp;gt;Sign In&amp;lt;/span&amp;gt; and view your ArcGIS Online items.
  &amp;lt;/div&amp;gt;

  &amp;lt;div id="personalizedPanel" style="display: none; padding: 5px; text-align: center;"&amp;gt;
    Welcome &amp;lt;span id="userId" style="font-weight: bold;"&amp;gt;&amp;lt;/span&amp;gt; &amp;amp;nbsp;-&amp;amp;nbsp;
    &amp;lt;span id="sign-out" class="action"&amp;gt;Sign Out&amp;lt;/span&amp;gt;
  &amp;lt;/div&amp;gt;

  &amp;lt;div id="itemGallery" class="esri-item-gallery" style="width: 100%;"&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>Wed, 25 Nov 2020 04:18:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-log-into-portal-with-jsapi-4/m-p/1004564#M70903</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2020-11-25T04:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to log into Portal with JSAPI 4??</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-log-into-portal-with-jsapi-4/m-p/1004572#M70904</link>
      <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous User&amp;nbsp;,&lt;/P&gt;&lt;P&gt;What is the authentication on your Portal for ArcGIS (ArcGIS Enterprise)?&lt;/P&gt;&lt;P&gt;On a side note, I troubleshooted with the following sample app using "ArcGIS Online" as the portal, and the OAuth workflow worked:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/identity-oauth-basic/index.html" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/sample-code/identity-oauth-basic/index.html&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Nov 2020 05:56:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-log-into-portal-with-jsapi-4/m-p/1004572#M70904</guid>
      <dc:creator>KavishGhime3</dc:creator>
      <dc:date>2020-11-25T05:56:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to log into Portal with JSAPI 4??</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-log-into-portal-with-jsapi-4/m-p/1004672#M70910</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/412931"&gt;@KavishGhime3&lt;/a&gt;&amp;nbsp; thanks for the reply.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can get it to work with my AGOL account. We have both AGOL and Portal both use Auth2.0 we use Okta to login .&lt;/P&gt;&lt;P&gt;I can get the simple app to work with AGOL but not Portal.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Nov 2020 15:12:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-log-into-portal-with-jsapi-4/m-p/1004672#M70910</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2020-11-25T15:12:52Z</dc:date>
    </item>
  </channel>
</rss>

