When to call EsriPortal.load() and IdentityManager.registerToken()

230
0
05-15-2023 04:00 PM
Labels (2)
BillSand
New Contributor II

Hello,

I have a bit of a "chicken and the egg" scenario with my code and was wondering what direction would be best to solve it.

I have an app that calls out to EsriPortal.load() in order to get the "allSSL" property in the returned data.  But in order to get my organization-specific "allSSL" setting, I need ArcGIS API to pass my token.  This means I have to call IdentityManager.registerToken(), but the parameter "ssl" can't be filled in until I know what my org's "allSSL" setting is.

My current workaround for this is to call IdentityManager.registerToken() twice.  Once before EsriPortal.load() and again afterwards in order to set the "ssl" parameter.  Without doing this, the first API call to /portals/self does not have a token and returned data is for an anonymous user.

Any ideas on how to make this better?

      IdentityManager.registerToken({
        expires: this.sessionSvc.TokenExpiration,
        server: EsriConfig.portalUrl,
        token: this.sessionSvc.ArcGISToken,
        userId: esriUser,
        ssl: true,
      });
      const portal = new EsriPortal();
      await portal.load();

      if (!portal.loadError) {
        this.portal = portal;

        IdentityManager.registerToken({
          expires: this.sessionSvc.TokenExpiration,
          server: EsriConfig.portalUrl,
          token: this.sessionSvc.ArcGISToken,
          userId: esriUser,
          ssl: this.portal.allSSL, // Now that I have an auth'd portal object, I can use allSSL property in registerToken.
        });
      }

An idea I had would be to manually construct the /portals/self API call with the token for the first call, and subsequent calls would have the token registered and use through the EsriPortal() object.  

Thanks,

Bill

0 Kudos
0 Replies