Solved! Go to Solution.
It might be because you generate tokens that are not associated to a referer.
Try by setting IdentityManager.Current.TokenGenerationReferer = <substring of your SL app URL> (e.g "http".
Without the code the only thing that we can do is to guess what you might possibly be doing wrong.
Post the code.
private void login_Click(object sender, RoutedEventArgs e)
{
string url = "https://www.arcgis.com/sharing/generateToken";
IdentityManager.Current.TokenGenerationReferer = <My IP Address which i got form http://Whatsmyip.com>;
IdentityManager.Current.GenerateCredentialAsync(url, UserName.Text, Password.Password,
(credential, ex) =>
{
if (ex == null)
{
AddFeatureLayers(credential.Token);
}
});
}
public void AddFeatureLayers(credential.Token){
MyFeatureLayer = new FeatureLayer
{
ID = "TrucksLayer",
Url = "<AGOL Feature Layer URL>",
Token = Token
};
MyFeatureLayer .OutFields.Add("*");
MyFeatureLayer .Initialized += new EventHandler<EventArgs>(MyFeatureLayer_Initialized);
MyFeatureLayer .InitializationFailed += new EventHandler<EventArgs>(MyFeatureLayer_InitializationFailed);
_map.Layers.Add(MyFeatureLayer );
}
void MyFeatureLayer_Initialized(object sender, EventArgs e)
{
Console.WriteLine("Layer initialized");
}
void MyFeatureLayer_InitializationFailed(object sender, EventArgs e)
{
Console.WriteLine("Layer not initialized");
}
public static Task<string> GetToken(string userName, string password)
{
var tcs = new TaskCompletionSource<string>();
string jsonData = "f=json&username=" + userName + "&password=" + password + "&referer=" + "http://arcgis.com" + "&request=getToken";
WebClient getTokenClient = new WebClient();
getTokenClient.Headers["Content-Type"] = "application/x-www-form-urlencoded";
getTokenClient.UploadStringCompleted += (sender, e) =>
{
JObject obj = JObject.Parse(e.Result.ToString());
tcs.TrySetResult(obj["token"].ToString());
};
getTokenClient.UploadStringAsync(new Uri("https://www.arcgis.com/sharing/rest/generateToken"), "Post", jsonData);
return tcs.Task;
}