Basemap not authorized using OAuth ESRI.ArcGISRunTime 200

609
5
03-09-2023 12:33 AM
Coolodporny
New Contributor II

After updating nuget package of the ESRI.ArcGISRunTime to 200 our Basemap stopped working. 
I am able to load portal features, display them on the map etc. 
When the program is trying to load Basemap I am getting an endless loop of prompts asking me to log in again. 
After investigating it deeper I think in the Basemap API calls there is no Token being passed. 

 

// This will create an endless login loop
var map = new Map(BasemapStyle.ArcGISDarkGray);

// This work fine
var map = new Map();

 

I am using the standard OAuth method with TokenAuthenticationType.OAuthAuthorizationCode.

 

ServerInfo portalServerInfo = new ServerInfo(esriPortalUri)
{
OAuthClientInfo =
new OAuthClientInfo(clientId, redirectUri, clientSecret),
TokenAuthenticationType = TokenAuthenticationType.OAuthAuthorizationCode
};
// Register the server information with the AuthenticationManager.
AuthenticationManager.Current.RegisterServer(portalServerInfo);
var credential = await AuthenticationManager.Current.GenerateCredentialAsync(esriPortalUri);

AuthenticationManager.Current.AddCredential((OAuthTokenCredential) credential );

 

Basemap prompt request without Token from SDK.

Coolodporny_0-1678350797840.png

Esri.ArcGISRuntime v200.0
Esri.ArcGISRuntime.WPF v200.0
Esri.ArcGISRuntime.Toolkit.WPF v200.0

0 Kudos
5 Replies
dotMorten_esri
Esri Notable Contributor

You should either:
1. Set the APIKey property on the Esri.ArcGISRuntime.ArcGISRuntimeEnvironment
or
2. Require the user to sign into an ArcGIS Online portal prior to opening a basemap.

0 Kudos
Coolodporny
New Contributor II

As mentioned in the ticket previous version of the nuget package (100+) was working fine. I am using the second option and asking the user the sign it by using the 

 // Use the OAuthAuthorize class (defined below) to show the login UI.
 AuthenticationManager.Current.OAuthAuthorizeHandler = new OAuthAuthorise();

 var credential = await 
 AuthenticationManager.Current.GenerateCredentialAsync(esriPortalUri);

 AuthenticationManager.Current.AddCredential((OAuthTokenCredential) credential 
 );

I am popping up a login window where the user is inserting their email and password. 
The credentials are working fine to get the personal data from EsriPortal like a list of the groups, feature services etc. But when it comes to BaseMap is not allowed. 

Maybe it has something to do with the Esri Portal version? Is there any limitation on which the Esri Portal version is supported by the newest Nuget version 200+?

0 Kudos
dotMorten
New Contributor III

Maybe it has something to do with the Esri Portal version?

Is this an on-premise portal? For basemaps to work, you'll need to sign into the arcgis.com / ArcGIS Online portal.

0 Kudos
Coolodporny
New Contributor II

That's maybe it. Indeed, I am using an on-premise portal. To make the base maps work from version 200+ will the user need to sign in to the on-premise portal and then to the official ArcGIS Online Portal?

0 Kudos
dotMorten
New Contributor III

Yes to use the arcgis location services you need to either:
1. Sign into ArcGIS.com before accessing the services
or
2. Set the ArcGISRuntimeEnvironment.APIKey property to an API Key you generate on the developer's website.

This isn't a new 200 thing. This was also a requirement in 100.x, unless you were still using the deprecated map services (which have been removed from 200).

0 Kudos