Can anyone provide me with an example of how to setup ESRI's IdentityManager class and/or ChallengeHandler .NET Toolkit component and use either of them to authenticate to your own Portal for ArcGIS instance?

I'm just picking up C# and .NET (day 2 of many to come) and their examples on developers.arcgis.com leave a lot to be desired for the .NET novice.

In particular, there don't seem to be any examples which clearly illustrate how the IdentityManager class should be referenced within an app, where in the code that reference should reside, what usage statements (if any) are required, etc.

Nor are there any full blown examples of how to use the ChallengeHandler in the .NET Toolkit.

The documentation at https://developers.arcgis.com/net/desktop/guide/use-arcgis-token-authentication.htm is too low level for me at this point and I've been struggling all day to wrap my feeble mind around it.

How would I authenticate the user of this app to my portal? My portal is bound to LDAP so I need an interface to challenge and accept the users credentials and send them to the Portal securely.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Esri.ArcGISRuntime.Controls;
using Esri.ArcGISRuntime.Portal;
using Esri.ArcGISRuntime.WebMap;
using Esri.ArcGISRuntime.Security;

namespace FirstApp
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>

    public partial class MainWindow : Window
        public MainWindow()
        private ArcGISPortal arcGISOnline;
        private ArcGISPortalItem selectedPortalItem;

        // changes the basemap layer
        private void baseMap_SelectionChanged(object sender, SelectionChangedEventArgs e)
            var combo = sender as ComboBox;
            var sel = combo.SelectedItem as ComboBoxItem;
            if (sel.Tag == null) { return; }

            //Find and remove the current basemap layer from the map
            if (mainMap == null) { return; }
            var oldBasemap = mainMap.Layers["BaseMap"];

            //Create a new basemap layer
            var newBaseMap = new Esri.ArcGISRuntime.Layers.ArcGISTiledMapServiceLayer();
            //Set the ServiceUri with the url defined for the ComboboxItem's Tag
            newBaseMap.ServiceUri = sel.Tag.ToString();
            //Give the layer an ID so it an still be found with the code above
            newBaseMap.ID = "BaseMap";

            //Insert the new basemap layer as the first (bottom) layer in the map
            mainMap.Layers.Insert(0, newBaseMap);

        // searches the portal for content
        private async void SearchButton_Click(object sender, RoutedEventArgs e)
                if (this.arcGISOnline == null) 
                    // create the uri for the portal 
                    var portalUri = new Uri("https://MyPortal.org.com/portal/sharing/rest");
                    // create the portal 
                    this.arcGISOnline = await ArcGISPortal.CreateAsync(portalUri); 
                    // How do I authenticate the user to the portal, challenging them for credentials?
                // create a variable to store search results
                IEnumerable<ArcGISPortalItem> results = null;
                // get the search term provided in the UI
                var searchTerm = this.SearchTextBox.Text.Trim();
                var searchItem = this.ItemTypeCombobox.SelectedValue.ToString();

                // build a query that searches for the specified searchItem type
                // ('web mapping application' is excluded from the search since 'web map' will match those item types too)
                var queryString = string.Format("\"{0}\" type:(\"{1}\" NOT \"web mapping application\")", searchTerm, searchItem);
                var searchParameters = new SearchParameters()
                    QueryString = queryString,
                    SortField = "avgrating",
                    SortOrder = QuerySortOrder.Descending,
                    Limit = 10
                // execute the search
                var itemSearch = await this.arcGISOnline.SearchItemsAsync(searchParameters);
                results = itemSearch.Results;

                // show the results in the list box
                this.ResultListBox.ItemsSource = results;
            catch (Exception ex)
                MessageBox.Show(ex.Message, "Error searching Portal");

        // resets the UI controls to keep them in sync with the currently selected portal item in the ResultsListBox
        private void ResetUI()
            // clear UI controls
            this.SnippetTextBlock.Text = "";
            this.ThumbnailImage.Source = null;
            this.ShowMapButton.IsEnabled = false;

        private void ResultSelectionChanged(object sender, SelectionChangedEventArgs e)

            // store the currently selected portal item
            this.selectedPortalItem = this.ResultListBox.SelectedItem as ArcGISPortalItem;
            if (this.selectedPortalItem == null) { return; }

            // show the portal item snippet (brief description) in the UI
            if (!string.IsNullOrEmpty(this.selectedPortalItem.Snippet))
                this.SnippetTextBlock.Text = this.selectedPortalItem.Snippet;

            // show a thumnail for the selected portal item (if there is one)
            if (this.selectedPortalItem.ThumbnailUri != null)
                var src = new BitmapImage(this.selectedPortalItem.ThumbnailUri);
                this.ThumbnailImage.Source = src;

            // enable the show map button when a web map portal item is chosen
            this.ShowMapButton.IsEnabled = (this.selectedPortalItem.Type == ItemType.WebMap);

        private async void ShowMapButton_Click(object sender, RoutedEventArgs e)
            // create a web map from the selected portal item
            var webMap = await WebMap.FromPortalItemAsync(this.selectedPortalItem);

            // load the web map into a web map view model
            var webMapVM = await WebMapViewModel.LoadAsync(webMap, this.arcGISOnline);

            // show the web map view model's map in the page's map view control
            this.mainMapView.Map = webMapVM.Map;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.