AnsweredAssumed Answered

ArcGIS Token not working properly

Question asked by shaikhrizuan on Jan 17, 2018

Hi,

 I am able to create ArcGIS Token for Secured Map Services using below code:

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

public string createToken()
{

string username = "siteadmin";
string password = "password";
string httpreferer = "http://MachineName/Test.html";
string generateTokenUrl = "https://MachineName:6443/arcgis/tokens/generateToken";
int exp = 60;


if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password))
{
TokenModel tokenModel = new TokenModel(username, password, httpreferer, exp);

string post = tokenModel.GetQueryStringParameter();
WebClient clientToken = new WebClient();
clientToken.Headers.Add("Content-Type: application/x-www-form-urlencoded");
string tokenResult = clientToken.UploadString(generateTokenUrl, post);
}

return tokenResult ;

}

public string GetQueryStringParameter()
{
return "f=" + this.f + "&username=" + this.username + "&password=" + this.password + "&referer=" + this.httpreferer + "&expiration=" + this.expiration;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

The token generated from the above code is like this : jRI_CQUsuxytOHJaXAxqLyHL9N1hgBDbM8RtNiJLbLM. The above is token is not respecting the above httpreferer URL. If i am adding the above token to the same map service for different site, its working. PFB Image for the same

Correct Referer URL

 Test.html

Incorrect Referer URL

 TokenHtml

But when i manually created the token (from https://MachineName:6443/arcgis/admin/generateToken  with the above referer (i.e.  http://MachineName/Test.html) , I am getting token like this: jRI_CQUsuxytOHJaXAxqL3WDbjsRIxmGyLfKmXuOBeWU0S9hoS57zDkwLmWWABZ1nVPoPItAxrXWuZubNgkT3z6b9ID404qlOW-IZC2y0BJDIneIoLQ8A6UxDuZZ7kgF

Which is quite big and working as expected (i.e. it is not allowing to access map service from any other http referer URL. One pop-up generated asking for user name & password.

 

So, I have change the "generateTokenUrl" parameter to https://MachineName:6443/arcgis/admin/generateToken and got the token as expected (i.e. quite big as above). But it is not working for any application (i.e. neither for the http referer URL nor any other application).A pop-up generated asking for user name & password. PFB Image

 Error

How to resolve this?

Outcomes