How do I Pass Token to Secure Service using ARCGIS JavaScript 4.x

597
2
05-05-2020 10:09 AM
CristianNovoa
New Contributor

Hi all, I'm trying to pass a token to a secure FeatureLayer like this:

var clientLayer = new FeatureLayer({
    url: "https://xxxxxxx/MapServer/0?token="+token,
    outFields: ["*"]
  });

Then I Get :

I also using these methods to get the token:

var def = esriId.generateToken(serverInfo, {
        "username": usuario,
        "password": pass,
        "client""referer",
        "referer": document.URL
      });
      def.then(function (value) {
        
        token = value.token;
        
        esriId.registerToken({
          server : server,
          token : token,
          expires : 90
        });

So, How is the correct way to pass the token to secure layer?

Thanks

0 Kudos
2 Replies
ReneRubalcava
Frequent Contributor II

You shouldn't need to pass the token manually.

If you create the ServerInfo to reference the server of your service, use generateToken, and then registerToken with the IdentityManager, and the API will automatically pass the token to the service with each request.

LeeIrminger
New Contributor II

Could someone please supply some sample code of what that process would look like please?


0 Kudos