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

05-05-2020 10:09 AM
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,
        "referer": document.URL
      def.then(function (value) {
        token = value.token;
          server : server,
          token : token,
          expires : 90

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


0 Kudos
2 Replies
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.

New Contributor II

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

0 Kudos