OAuth2 - SAML on ArcGIS Enterprise - does this give you access to basemaps?

524
5
05-30-2023 12:02 PM
ChrisCrowe
New Contributor II

I am creating a WPF application and I am using the simple example online at Display map | ArcGIS Maps SDK for .NET | ArcGIS Developers

If I do not specify an API key then it displays a blank window with Powered by ESRI.

If I specify an API KEY using this code then it displays a map as in the example.

public MainWindow()
{
InitializeComponent();/Esri.ArcGISRuntime.ArcGISRuntimeEnvironment.ApiKey = "AAPKa6a58defb24a41.............dj6-9WIzn5QX_ECKPq52HH8";

}

In my case I am wanting to use OKTA (SAML) authentication to connect to an ARCGIS enterprise system. I have this working using the following code.

 

ArcGISRuntimeEnvironment.Initialize((options) => { });
string serverUrl = "https://portal.domain.com/portal/";
var clientId = "8qOp0LS.......WwhZ6R";
var serverInfo = new ServerInfo(new Uri(serverUrl))
{
 OAuthClientInfo = new OAuthClientInfo(clientId, new Uri(@"vmsUI://auth"), ""),
 TokenAuthenticationType = TokenAuthenticationType.OAuthAuthorizationCode
};

AuthenticationManager.Current.RegisterServer(serverInfo);
AuthenticationManager.Current.OAuthAuthorizeHandler = new OAuthAuthorise();
var currentToken = (OAuthTokenCredential)AuthenticationManager.Current.FindCredential(new Uri(serverUrl), AuthenticationType.Token);
if (currentToken == null)
{
 currentToken = (OAuthTokenCredential)await Task.Run(async () => await                                      AuthenticationManager.Current.GenerateCredentialAsync(new Uri(serverUrl)), CancellationToken.None);

AuthenticationManager.Current.AddCredential(currentToken);
var portal = await Esri.ArcGISRuntime.Portal.ArcGISPortal.CreateAsync(new Uri(serverUrl), false);
var licenseInfo = await portal.GetLicenseInfoAsync();
var licenseResult = ArcGISRuntimeEnvironment.SetLicense(licenseInfo);
}

 

 

In my case the licenseResult returns a property of LicenseStatus: Valid

I can call ArcGISRuntimeEnvironemnt.GetLicense() and it returns the following

ChrisCrowe_0-1685473457856.png

If I look at ArcGISRuntimeEnvironment.ApiKey it is set to ""

No map is displayed.

In the output window I see

ArcGIS Maps SDK: Load Error: Basemap
Esri.ArcGISRuntime.Http.ArcGISWebException
Token Required.
ArcGIS Maps SDK: Load Error: Map
Esri.ArcGISRuntime.Http.ArcGISWebException
Token Required.

So finally my question is what do I need to do to get  this to work - I must be missing a step with a token but I do not know what.

Chris

5 Replies
ChrisCrowe
New Contributor II

I have found something very interesting.

I was working with v200.1 (latest version of the runtime) and was mainly using a pretty standard map initializer.

Map myMap = new Map(BasemapStyle.ArcGISImageryStandard);

This base map points to 

https://basemaps-api.arcgis.com/arcgis/rest/services/styles/ArcGIS:Imagery:Standard

We have another WPF app that was working but it was using 100.15.0 and it used this map initializer

 

Map myMap = new Map(SpatialReferences.WebMercator) { Basemap = Basemap.CreateDarkGrayCanvasVector() };

 

 

You cannot initialize the map in 200.1 using the format above. The method was deprecated even back in 100.15.0 and it tells you to use BasemapStyle.ArcGISDarkGray

But BasemapStyle.ArcGISDarkGray points to 

https://basemaps-api.arcgis.com/arcgis/rest/services/styles/ArcGIS:DarkGray

So I changed my test app to 100.15.0 instead of 200.1 

My map will show if I use the following initializer

 

Map myMap = new Map(SpatialReferences.WebMercator) { Basemap = Basemap.CreateDarkGrayCanvasVector() };

 

 

but not using BasemapStyle.ArcGISDarkGray

This is what the basemap shows when using CreateDarkGrayCanvasVector - no URI at all is set.

ChrisCrowe_0-1685483973300.png

So I assume that our enterprise arcgis server has no base maps and even if it did I would need to specify a basemap which is on the same server and not use the BaseMapStyle which all go to https://basemaps-api.arcgis.com

So I either have to leave the app at 100.15.x and have this basemap or upgrade and have no base map!

 

 

0 Kudos
DiveshGoyal
Esri Regular Contributor

You are on the right track.
The services used by the BasemapStyle API under the hood are the standard endpoints from ArcGIS Location services. These are accessible via API keys or by ArcGIS Developer or Online accounts. You cannot use ArcGIS Enterprise accounts with these.




0 Kudos
ChrisCrowe
New Contributor II

Ah Good to know about the difference here.

So basically we can not upgrade to the new API since it no longer supports the internal base map we are using. Unless we license the base maps as well.

Chris

 

0 Kudos
dotMorten_esri
Esri Notable Contributor

You can use your own internal basemaps - it's only the pre-defined arcgis online basemaps (ie the ones that use the BasemapStyle) which require an API Key

0 Kudos
ChrisCrowe
New Contributor II

Right makes sense, I assume that the CreateDarkGrayCanvasVector was something internal to the 100.x runtime that is now removed.

Basemap.CreateDarkGrayCanvasVector() 

 

I am sure we can get an API key to use for the base map if we upgrade to 200.x

I also assume that setting the ArcGISRuntimeEnvironment.ApiKey does not affect the OAuth which uses 

ArcGISRuntimeEnvironment.SetLicense(licenseInfo);

 

Thanks for your help.

Chris

 

0 Kudos