AnsweredAssumed Answered

Get token from Esri Online to access secure service

Question asked by bridgji on Jan 27, 2016
Latest reply on Jan 27, 2016 by bridgji

I'm having trouble retriving a token to access a secure service online. I'm using a developer account. When I run it against a local install of ArcGIS Server it works fine  I'm not 100% sure what the tokenurl would be and if the userid /password would just be the login I have for my developer site.

Thanks

Jim

 

 

I'm using code similar to the following to retrive the token:

 

public Dictionary<string, string> GetToken(string username, string password, string tokenUrl)

 

Dictionary<string, string> dictionary = new Dictionary<string, string>();

 

MapTalk mt = new MapTalk();

 

var myToken = "";

 

if (tokenUrl != "")

 

//#######################


var data = new NameValueCollection();

 

"username"] = username;

 

"password"] = password;

 

"expires"] = "1";

 

"f"] = "json";

 

JavaScriptSerializer jserialize = new JavaScriptSerializer();

 

TokenInfo x = jserialize.Deserialize<TokenInfo>(_getResponse(data, tokenUrl));

 

var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

 

var expire = epoch.AddMilliseconds(x.expires).ToLocalTime();

 

"token", myToken);

 

"expire",expire.ToString());

 

return dictionary;

 

else


"token","");

 

return dictionary;

 

public class TokenInfo


public string token { get; set; }

 

public long expires { get; set; }

 

public bool ssl { get; set; }

 

private string _getResponse(NameValueCollection data, string url)

 

string responseData;

 

var webClient = new WebClient();

 

var response = webClient.UploadValues(url, data);

 

Encoding.UTF8.GetString(response);

 

return responseData;

 

 

 

 

 

Outcomes