Problems with using token and javascript API

3559
1
Jump to solution
09-01-2017 01:01 AM
LarsFagerbakke
New Contributor III

Hello!

I'm implementing featurelayers from a companies arcgis server and until now I've been polled for username and password in the website I'm making. Its a webresource inside Dynamics so authentication is already handled. I see the arcgis server has the feature to create tokens at .../arcgis/tokens and I created one for my application.

I'm unsure of what client, as I have not declared it somewhere. I've tried;

- HTTP Referer with the address of the dynamics installation (something.crm3.dynamics.com)

- IP (ip of something.crm3.dynamics.com)

- Request IP (but that would not work as I'm doing the request from my work laptop)

I've implemented the token as stated in the documentation:

var layer = new FeatureLayer({
url: "https://foo.boo.no/arcgis/rest/services/appname1/appname2/MapServer/0",
token: "<token>"
});

map.add(layer);

The <token> is the one generated from .../arcgis/tokens.

I tried all the types of clients as tokens in the FeatureLayer request but nothing changes, I am still prompted to insert username and password.

Does anyone have and idea? I need to replace the popup of username and password with the token in the background.

Tags (1)
1 Solution

Accepted Solutions
LarsFagerbakke
New Contributor III

Okey, got what I wanted! 

This problem was solved by removing the token from the layer calls and using IdentityManager ahead of all other calls instead.

The documentation is bad, but what I did was adding IdentityManager by adding the reference to "esri/identity/IdentityManager" and the member IdentityManager. 

So at the start of the function() function (:-)) I simply added

var token = {
'server': 'https://foo.boo.no/arcgis/rest/services',
'token': '<token>',
};
IdentityManager.registerToken(token);

and then the rest of my logic. Problem solved. But I wish the documentation was a little more helpful with the IdentityManager object and why did not the token property of the FeatureLayer work?

View solution in original post

1 Reply
LarsFagerbakke
New Contributor III

Okey, got what I wanted! 

This problem was solved by removing the token from the layer calls and using IdentityManager ahead of all other calls instead.

The documentation is bad, but what I did was adding IdentityManager by adding the reference to "esri/identity/IdentityManager" and the member IdentityManager. 

So at the start of the function() function (:-)) I simply added

var token = {
'server': 'https://foo.boo.no/arcgis/rest/services',
'token': '<token>',
};
IdentityManager.registerToken(token);

and then the rest of my logic. Problem solved. But I wish the documentation was a little more helpful with the IdentityManager object and why did not the token property of the FeatureLayer work?