<?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: IdentityManager problems in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/identitymanager-problems/m-p/1024826#M71703</link>
    <description>&lt;P&gt;What do you get if you do the stringify / parse combo on your t.state?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;JSON.parse(JSON.stringify(t.state))),&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or wrap it in another JSON.parse()?&lt;/P&gt;</description>
    <pubDate>Tue, 09 Feb 2021 12:19:51 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2021-02-09T12:19:51Z</dc:date>
    <item>
      <title>IdentityManager problems</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/identitymanager-problems/m-p/1024161#M71675</link>
      <description>&lt;P&gt;I've been creating a web app utilizing&amp;nbsp;&lt;A href="https://github.com/Esri/esri-react-boot" target="_self"&gt;Esri React Boot&lt;/A&gt;&amp;nbsp;(which is a boilerplate that uses React, Redux plus Javascript). The app utilizes ArcGIS REST JS to login a user using a&amp;nbsp;&lt;A href="https://esri.github.io/arcgis-rest-js/api/auth/UserSession/" target="_self"&gt;UserSession&lt;/A&gt;&amp;nbsp;, then stores the login info from UserSession to a Redux store.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem I'm encountering, is that when I try to register this UserSession to a Javascript 4.18 &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-identity-IdentityManager.html#registerToken" target="_self"&gt;IdentityManager&lt;/A&gt;&amp;nbsp;(using &lt;A href="https://esri.github.io/arcgis-rest-js/api/auth/UserSession/#toCredential" target="_self"&gt;UserSession.toCredentials()&lt;/A&gt; and &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-identity-IdentityManager.html#registerOAuthInfos" target="_self"&gt;IdentityManager.registerToken()&lt;/A&gt;) after the user has logged in, I get an error: "Uncaught SyntaxError: Unexpected token in JSON at position 0."&amp;nbsp;The goal is that once the user is logged in once, they don't have to login again to access portal items but can use the existing login credentials to access any private items.&lt;/P&gt;&lt;P&gt;After doing a little digging, it looks like this unexpected token is the Client ID I'm using in&amp;nbsp;UserSession.completeOAuth2() and is getting tripped up on this part of the code:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;  _getOAuthHash() {
    let e = window.location.hash;
    if (e) {
      '#' === e.charAt(0) &amp;amp;&amp;amp; (e = e.substring(1));
      const t = u(e);
      let r = !1;
      t.access_token &amp;amp;&amp;amp; t.expires_in &amp;amp;&amp;amp; t.state &amp;amp;&amp;amp; t.hasOwnProperty('username')
        ? ((t.state = JSON.parse(t.state)), (this._oAuthHash = t), (r = !0))
        : t.error &amp;amp;&amp;amp;
          t.error_description &amp;amp;&amp;amp;
          (console.log('IdentityManager OAuth Error: ', t.error, ' - ', t.error_description),
          'access_denied' === t.error &amp;amp;&amp;amp; (r = !0)),
        r &amp;amp;&amp;amp; (window.location.hash = ('object' == typeof t.state &amp;amp;&amp;amp; t.state.hash) || '');
    }
  }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;where for some reason t.state is just returning the clientID string and not a JSON to be parsed.&lt;/P&gt;&lt;P&gt;Any ideas what's going wrong? This happens whenever I use IdentityManager (even if I'm just doing a console.log to see if it's already initialized)&lt;/P&gt;&lt;P&gt;Here's the code I'm using to register with IdentityManager:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function completeSignIn(options) {
  const {
    portalUrl = 'https://www.arcgis.com/',
    clientId,
    sessionId = `${portalUrl}_session`
  } = options;

  const session = UserSession.completeOAuth2({ clientId, portalUrl });
  const credentials = session.toCredential();
  IdentityManager.registerToken(credentials);

  const token = session.token;

  saveSession(session, sessionId);

  const user = await session.getUser();

  const portal = await getPortal(null, {
    portal: session.portal,
    authentication: session
  });

  return { user, portal, token };
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 06 Feb 2021 19:20:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/identitymanager-problems/m-p/1024161#M71675</guid>
      <dc:creator>JJames</dc:creator>
      <dc:date>2021-02-06T19:20:37Z</dc:date>
    </item>
    <item>
      <title>Re: IdentityManager problems</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/identitymanager-problems/m-p/1024826#M71703</link>
      <description>&lt;P&gt;What do you get if you do the stringify / parse combo on your t.state?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;JSON.parse(JSON.stringify(t.state))),&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or wrap it in another JSON.parse()?&lt;/P&gt;</description>
      <pubDate>Tue, 09 Feb 2021 12:19:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/identitymanager-problems/m-p/1024826#M71703</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-02-09T12:19:51Z</dc:date>
    </item>
  </channel>
</rss>

