I have recently started working on ArcGIS API's. I am able to add feature layers/ edit layers etc. However I want to validate user id and password using ArcGIS API's and generate token once the credentials are verified.
I tried couple of ways as below but could not accomplish the results.
```
function login(user, password)
{
var serverInfo = new ServerInfo();
serverInfo.server = 'https://myorganizatoon.arcgis.com/';
serverInfo.tokenServiceUrl="http://myorganization.arcgis.com/arcgis/tokens/generateToken";
//serverInfo.tokenServiceUrl=http://www.arcgis.com/arcgis/tokens/generateToken";
//(I don't know which of these two links are correct for the serverinfo, that's why I tried both. Please suggest me which one is correct?)
esriId.registerServers([serverInfo]);
var serverInfo = esriId.serverInfos[0];
var userInfo = {};
userInfo.username = "myusername";
userInfo.password = "mypassword";
esriId.generateToken(serverInfo, userInfo).then(function (response)
{
response.server = serverInfo.server;
response.userId = user;
esriId.registerToken(response);
});
}
```
I am using ArcGIS API for javascript 3.31.
Please suggest.
Here's a sample code that could be useful: ArcGISSamples/identityManagerBase.html at master · vcoelho/ArcGISSamples · GitHub