Access secure resources from ArcGIS Portal with ArcGIS API for javascript without login pop-up window

04-07-2020 01:42 AM
New Contributor II

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 = '';
//(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?)
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;

I am using ArcGIS API for javascript 3.31.
Please suggest.

0 Kudos
1 Reply
New Contributor III
0 Kudos