Select to view content in your preferred language

Unable to use browser login when WPF app packaged

52
1
16 hours ago
ViktorSafar
Occasional Contributor II

I created a WPF app using the ArcGIS Maps SDK .NET WPF App (Esri) template.

I copied in the ArcGISLoginPrompt class from the WPF samples.

I created a new app in AGOL and updated the appId in the WPF app.

The app runs, I am presented with the AGOL login window, can log in, and the app presents the protected resource (basemap, as configured from the Visual Studio template).

 

I then added a Windows Application Packaging Project project and added the WPF app as a reference.

Running the app via the packaging project I get
Esri.ArcGISRuntime.Http.ArcGISWebException: 'Unable to generate token.'

from within 

credential = await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri);

 

If I switch Startup project back to the WPF app, it works fine again.

 

Using Fiddler I can see that when running via the packaging project, the app is calling /sharing/generateToken without any credentials so that error makes sense. The question is why is it calling that and not presenting the browser window.

 

Repro repo https://github.com/viktor-safar-geodata/wpf-arcgis-packaged

0 Kudos
1 Reply
dotMorten_esri
Esri Notable Contributor

I see the same behavior for both. I wonder if it's because you got persistence enabled ?

Try removing this line: https://github.com/viktor-safar-geodata/wpf-arcgis-packaged/blob/main/WpfMapApp1/App.xaml.cs#L27

It has no effect on an unpackaged app, but it makes sure you don't need to sign in over and over again if you're using a packaged app. So if you already signed in earlier, it won't be asking you again until you actively sign out by calling

await AuthenticationManager.Current.RemoveAndRevokeAllCredentialsAsync();

0 Kudos