AnsweredAssumed Answered

Using basemaps requiring credentials

Question asked by dhope@ara.com on Feb 8, 2017
Latest reply on Feb 10, 2017 by dhope@ara.com

I'm having the darnedest time creating a basemap based on a ArcGISTiledLayer that is coming from a Uri that requires credentials...

 

So here's what I'm doing:

        CurrentBasemapUrl = "https://tiledbasemaps.arcgis.com/arcgis/rest/services/World_Street_Map/MapServer"

      var server = CurrentBasemapUrl; // "https://maps.gvs.nga.mil/arcgis/rest/services/Basemap/NGA_World_Imagery_2D/MapServer";

 Esri.ArcGISRuntime.Security.AuthenticationManager.Current.ChallengeHandler = new ChallengeHandler(myChallengeHandler);

 myMap.Basemap = new Basemap(new ArcGISTiledLayer(new Uri(server)));

 

for myChallengeHandler, I have this:

static async Task<Credential> myChallengeHandler(CredentialRequestInfo cri)
{
   switch(cri.AuthenticationType)
   {
      case AuthenticationType.Token:
      var options = new Esri.ArcGISRuntime.Security.GenerateTokenOptions() { Referer = new Uri(CurrentBasemapUrl)};
      var user = "myusernameishere";
      var pass = "mypasswordishere";
      var cred = await AuthenticationManager.Current.GenerateCredentialAsync(
         new Uri("https://www.arcgis.com/sharing/rest/generatetoken"),user, pass, options);


      return cred;
   }
   return null;
}

 

when I do this, all I get is a grid, no maps. But I'm not getting any errors. Any ideas?

 

Using the same URL, I was able to successfully download a tile package.

 

If I change the URL to "http://services.arcgisonline.com/arcgis/rest/services/World_Street_Map/MapServer" (which doesn't require any creditials, it works fine.

 

Any help?

Outcomes