<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Help with OAuth in .NET Maps SDK Questions</title>
    <link>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1342196#M12230</link>
    <description>&lt;P&gt;OK, so this is interesting.&lt;/P&gt;&lt;P&gt;If I use the code in the OAuth sample from the "ArcGIS Maps SDK Sample for .NET", and just sub the webmap ID for the ID of my webmap, everything seems to work OK.&amp;nbsp; In this OAuth sample it seems to use a class called "ArcGISLoginPrompt" and is a bit hard to follow exactly what is going on.&lt;/P&gt;&lt;P&gt;Can anyone explain the difference between the OAuth tutorial which I have been struggling to get to work (&lt;A href="https://developers.arcgis.com/net/security-and-authentication/tutorials/access-services-with-oauth-2-0/" target="_blank"&gt;https://developers.arcgis.com/net/security-and-authentication/tutorials/access-services-with-oauth-2-0/&lt;/A&gt;) and the sample in the .NET sample code (&lt;A href="https://developers.arcgis.com/net/uwp/sample-code/" target="_blank"&gt;https://developers.arcgis.com/net/uwp/sample-code/&lt;/A&gt;).&lt;/P&gt;&lt;P&gt;I still don't understand why I can't get the tutorial sample code to work, but if I can get a better understanding of the other sample project maybe I can roll with that.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;</description>
    <pubDate>Thu, 26 Oct 2023 17:42:51 GMT</pubDate>
    <dc:creator>BrianBulla1</dc:creator>
    <dc:date>2023-10-26T17:42:51Z</dc:date>
    <item>
      <title>Help with OAuth</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1335080#M12166</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm just starting with the Maps SDK today, so sorry in advance for the stupid questions.&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;So I'm trying to do something that I think should be super simple, but I cannot for the life of me get it to work.&amp;nbsp; I'm using the DisplayAMap sample, changing the portal item to one under my AGOL account, and trying to display it.&amp;nbsp; The missing componenet is the OAuth, since I'll need to enter a username/password to get to the webmap.&lt;/P&gt;&lt;P&gt;I'm looking at the "Secutrity" samples in the .NET WPF app, but don't quite understand how to integrate it into what I already have working in the DisplayAMap Sample.&lt;/P&gt;&lt;P&gt;There seems to be this "ArcGISLoginPrompt.cs" file, that doesn't display the code for in the app.&amp;nbsp; I'm guessing that's an important part of it??&lt;/P&gt;&lt;P&gt;Sorry for the cryptic question....I just have no clue what to even ask.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2023 18:30:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1335080#M12166</guid>
      <dc:creator>BrianBulla1</dc:creator>
      <dc:date>2023-10-04T18:30:49Z</dc:date>
    </item>
    <item>
      <title>Re: Help with OAuth</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1335211#M12168</link>
      <description>&lt;P&gt;A little more detail about what you issues are, platform.&amp;nbsp; The security sample in github are hard to follow because they use shared code, better to follow in the sample explanation on the site.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2023 22:49:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1335211#M12168</guid>
      <dc:creator>JoeHershman</dc:creator>
      <dc:date>2023-10-04T22:49:00Z</dc:date>
    </item>
    <item>
      <title>Re: Help with OAuth</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1336637#M12177</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/7529"&gt;@JoeHershman&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;&lt;P&gt;So basically what I have done is trying to combine the Display A Map tutorial and the Oath 2.0 tutorial found here (&lt;A href="https://developers.arcgis.com/net/tutorials/" target="_blank"&gt;https://developers.arcgis.com/net/tutorials/&lt;/A&gt;) and get it to work with a secured webmap in my own AGOL account.&lt;/P&gt;&lt;P&gt;I can get it to build with no errors, but nothing is showing up in the WPF form.&amp;nbsp; It's just a blank map.&lt;/P&gt;&lt;P&gt;Not quite sure how to troubleshoot it.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2023 16:38:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1336637#M12177</guid>
      <dc:creator>BrianBulla1</dc:creator>
      <dc:date>2023-10-10T16:38:18Z</dc:date>
    </item>
    <item>
      <title>Re: Help with OAuth</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1336656#M12179</link>
      <description>&lt;P&gt;It seems to be stalling at this line, where the web map is getting created.&amp;nbsp; It never gets to the point where it asks for the username/password for AGOL.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BrianBulla1_0-1696959154806.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/82786i481F7333268A148B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="BrianBulla1_0-1696959154806.png" alt="BrianBulla1_0-1696959154806.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2023 17:32:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1336656#M12179</guid>
      <dc:creator>BrianBulla1</dc:creator>
      <dc:date>2023-10-10T17:32:42Z</dc:date>
    </item>
    <item>
      <title>Re: Help with OAuth</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1336894#M12182</link>
      <description>&lt;P&gt;Hard to know what you have gotten done.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Have you setup the OAuth app inside of ArcGIS Online?&amp;nbsp; This is discussed in the sample&amp;nbsp;&lt;A href="https://developers.arcgis.com/net/wpf/sample-code/authenticate-with-oauth/" target="_self"&gt;Authenticate with OAuth&lt;/A&gt;&amp;nbsp;&lt;OL&gt;&lt;LI&gt;You can do through dev account if you are using AGOL tied to dev account&amp;nbsp;&lt;A href="https://developers.arcgis.com/documentation/mapping-apis-and-services/security/tutorials/register-your-application/" target="_self"&gt;Register an OAuth application&lt;/A&gt;&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;Do on AGOL, this is a bit old so there are slight GUI changes&amp;nbsp;&lt;A href="https://community.esri.com/t5/developers-blog/how-to-implement-oauth-2-0-for-arcgis/ba-p/891853" target="_self"&gt;How to Implement OAuth 2.0 for ArcGIS&lt;/A&gt;&amp;nbsp;&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;You need to implement the IOAuthAuthorizeHandler.&amp;nbsp; See at bottom&lt;/LI&gt;&lt;LI&gt;Wire up everything.&amp;nbsp; This is done before you can make a call that will open the OAuth window.&amp;nbsp; AppClientID, ClientSecret, RedirectUrl all come from the OAuth app in AGOL (or dev center)&lt;/LI&gt;&lt;/OL&gt;&lt;LI-CODE lang="csharp"&gt;private void Initialize(Uri serverUri)
{
	try
	{
		var redirectUri = new Uri(RedirectUrl);
		ServerInfo serverInfo = new ServerInfo(serverUri)
		{
			TokenAuthenticationType = TokenAuthenticationType.OAuthAuthorizationCode,
			OAuthClientInfo = new OAuthClientInfo(AppClientId, redirectUri)
			{
				UserInterfaceStyle = UserInterfaceStyle.Dark,
				ClientSecret = ClientSecret,
			},

		};

		AuthenticationManager.Current.RegisterServer(serverInfo);
		AuthenticationManager.Current.OAuthAuthorizeHandler = _oAuthAuthorizeHandler;
		AuthenticationManager.Current.ChallengeHandler = new ChallengeHandler(CreateCredentialAsync);
	}
	catch (Exception e)
	{
		_log?.Log(e.Message, Category.Exception, Priority.None);
	}
}

private async Task&amp;lt;Credential&amp;gt; CreateCredentialAsync(CredentialRequestInfo info)
{
	try
	{
		Credential credential = null;

		try
		{
			if (info.ServiceUri != null)
			{
				var options = new GenerateTokenOptions { TokenExpirationInterval = TimeSpan.FromDays(1) };
				credential = await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, options);
				
				AuthenticationManager.Current.AddCredential(credential);

				ConnectionStatus = ConnectionStatus.Connected;
			}
		}
		catch (OperationCanceledException)
		{
			ConnectionStatus = ConnectionStatus.NotConnected;
			// Login was cancelled, no need to display an error to the user.
		}
		catch (Exception e)
		{
			_log.Log(e.Message, Category.Warn, Priority.None);
		}

		return credential;

	}
	catch (Exception)
	{
		return null;
	}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One annoying with the API is that connecting to Portal does not automatically trigger the the challenge handler.&amp;nbsp; So you have to have the code in the method that connects to portal that, imo, should only be in ChallengeHandler&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public async Task&amp;lt;ArcGISPortal&amp;gt; OpenPortalAsync(string portalUrl, bool refresh = false)
{
	var sharingUri = GetSharingUri(portalUrl);
        //THIS LINE SHOULD OPEN WINDOW!
	var credential = await AuthenticationManager.Current.GenerateCredentialAsync(sharingUri);

	AuthenticationManager.Current.AddCredential(credential);

	_portal = await ArcGISPortal.CreateAsync(sharingUri);
	PortalUser = _portal.User;

	return _portal;
}

private Uri GetSharingUri(string portalUrl)
{
	return new Uri($"{portalUrl}/sharing/rest");
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;IOAuthAuthorizeHandler implementation from esri sample:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;// In a desktop (WPF) app, an IOAuthAuthorizeHandler component is used to handle some of the OAuth details. Specifically, it
//     implements AuthorizeAsync to show the login UI (generated by the server that hosts secure content) in a web control.
//     When the user logs in successfully, cancels the login, or closes the window without continuing, the IOAuthAuthorizeHandler
//     is responsible for obtaining the authorization from the server or raising an OperationCanceledException.
public class OAuthAuthorizeHandler : IOAuthAuthorizeHandler
{
	// Window to contain the OAuth UI.
	private Window _authWindow;

	// Use a TaskCompletionSource to track the completion of the authorization.
	private TaskCompletionSource&amp;lt;IDictionary&amp;lt;string, string&amp;gt;&amp;gt; _tcs;

	// URL for the authorization callback result (the redirect URI configured for your application).
	private string _callbackUrl;

	// URL that handles the OAuth request.
	private string _authorizeUrl;

	// Function to handle authorization requests, takes the URIs for the secured service, the authorization endpoint, and the redirect URI.
	public Task&amp;lt;IDictionary&amp;lt;string, string&amp;gt;&amp;gt; AuthorizeAsync(Uri serviceUri, Uri authorizeUri, Uri callbackUri)
	{
		if (_tcs != null &amp;amp;&amp;amp; !_tcs.Task.IsCompleted)
			throw new Exception("Task in progress");

		_tcs = new TaskCompletionSource&amp;lt;IDictionary&amp;lt;string, string&amp;gt;&amp;gt;();

		// Store the authorization and redirect URLs.
		_authorizeUrl = authorizeUri.AbsoluteUri;
		_callbackUrl = callbackUri.AbsoluteUri;

		// Call a function to show the login controls, make sure it runs on the UI thread for this app.
		Dispatcher dispatcher = Application.Current.Dispatcher;
		if (dispatcher == null || dispatcher.CheckAccess())
		{
			AuthorizeOnUIThread(_authorizeUrl);
		}
		else
		{
			Action authorizeOnUIAction = () =&amp;gt; AuthorizeOnUIThread(_authorizeUrl);
			dispatcher.BeginInvoke(authorizeOnUIAction);
		}

		// Return the task associated with the TaskCompletionSource.
		return _tcs.Task;
	}

	// Challenge for OAuth credentials on the UI thread.
	private void AuthorizeOnUIThread(string authorizeUri)
	{
		// Create a WebBrowser control to display the authorize page.
		WebBrowser webBrowser = new WebBrowser();

		// Handle the navigation event for the browser to check for a response to the redirect URL.
		webBrowser.Navigating += WebBrowserOnNavigating;

		// Display the web browser in a new window.
		_authWindow = new Window
		{
			Content = webBrowser,
			Width = 450,
			Height = 450,
			WindowStartupLocation = WindowStartupLocation.CenterOwner
		};

		// Set the app's window as the owner of the browser window (if main window closes, so will the browser).
		if (Application.Current != null &amp;amp;&amp;amp; Application.Current.MainWindow != null)
		{
			_authWindow.Owner = Application.Current.MainWindow;
		}

		// Handle the window closed event then navigate to the authorize url.
		_authWindow.Closed += OnWindowClosed;
		webBrowser.Navigate(authorizeUri);

		// Display the window.
		_authWindow.ShowDialog();
	}

	// Handle the browser window closing.
	private void OnWindowClosed(object sender, EventArgs e)
	{
		// If the browser window closes, return the focus to the main window.
		if (_authWindow != null &amp;amp;&amp;amp; _authWindow.Owner != null)
		{
			_authWindow.Owner.Focus();
		}

		// If the task wasn't completed, the user must have closed the window without logging in.
		if (!_tcs.Task.IsCompleted)
		{
			// Set the task completion source exception to indicate a canceled operation.
			_tcs.SetCanceled();
		}

		_authWindow = null;
	}

	// Handle browser navigation (content changing).
	private void WebBrowserOnNavigating(object sender, NavigatingCancelEventArgs e)
	{
		// Check for a response to the callback url.
		const string portalApprovalMarker = "/oauth2/approval";
		WebBrowser webBrowser = sender as WebBrowser;

		Uri uri = e.Uri;

		// If no browser, uri, or an empty url, return.
		if (webBrowser == null || uri == null || string.IsNullOrEmpty(uri.AbsoluteUri))
			return;

		// Check for redirect.
		bool isRedirected = uri.AbsoluteUri.StartsWith(_callbackUrl) ||
			_callbackUrl.Contains(portalApprovalMarker) &amp;amp;&amp;amp; uri.AbsoluteUri.Contains(portalApprovalMarker);

		// Check if browser was redirected to the callback URL. (This indicates succesful authentication.)
		if (isRedirected)
		{
			e.Cancel = true;

			// Call a helper function to decode the response parameters.
			IDictionary&amp;lt;string, string&amp;gt; authResponse = DecodeParameters(uri);

			// Set the result for the task completion source.
			_tcs.SetResult(authResponse);

			// Close the window.
			if (_authWindow != null)
			{
				_authWindow.Close();
			}
		}
	}

	private static IDictionary&amp;lt;string, string&amp;gt; DecodeParameters(Uri uri)
	{
		// Create a dictionary of key value pairs returned in an OAuth authorization response URI query string.
		string answer = "";

		// Get the values from the URI fragment or query string.
		if (!string.IsNullOrEmpty(uri.Fragment))
		{
			answer = uri.Fragment.Substring(1);
		}
		else
		{
			if (!string.IsNullOrEmpty(uri.Query))
			{
				answer = uri.Query.Substring(1);
			}
		}

		// Parse parameters into key / value pairs.
		Dictionary&amp;lt;string, string&amp;gt; keyValueDictionary = new Dictionary&amp;lt;string, string&amp;gt;();
		string[] keysAndValues = answer.Split(new[] { '&amp;amp;' }, StringSplitOptions.RemoveEmptyEntries);
		foreach (string kvString in keysAndValues)
		{
			string[] pair = kvString.Split('=');
			string key = pair[0];
			string value = string.Empty;
			if (key.Length &amp;gt; 1)
			{
				value = Uri.UnescapeDataString(pair[1]);
			}

			keyValueDictionary.Add(key, value);
		}

		// Return the dictionary of string keys/values.
		return keyValueDictionary;
	}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2023 12:49:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1336894#M12182</guid>
      <dc:creator>JoeHershman</dc:creator>
      <dc:date>2023-10-11T12:49:43Z</dc:date>
    </item>
    <item>
      <title>Re: Help with OAuth</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1337311#M12184</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/7529"&gt;@JoeHershman&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;&lt;P&gt;If I use that Authenticate with OAuth sample and modify the code, I can get it to work with my web map I am testing with, so I must have the OAuth setup properly in my Developers Account.&lt;/P&gt;&lt;P&gt;I'll have to figure out how to add what is in this OAuth sample into my own app.&amp;nbsp; It seems quite different than the sample I have been using here:&amp;nbsp;&amp;nbsp;&lt;A href="https://developers.arcgis.com/net/security-and-authentication/tutorials/access-services-with-oauth-2-0/" target="_blank"&gt;https://developers.arcgis.com/net/security-and-authentication/tutorials/access-services-with-oauth-2-0/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Oct 2023 15:23:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1337311#M12184</guid>
      <dc:creator>BrianBulla1</dc:creator>
      <dc:date>2023-10-12T15:23:28Z</dc:date>
    </item>
    <item>
      <title>Re: Help with OAuth</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1338259#M12187</link>
      <description>&lt;P&gt;OK....so I've gotten things to the point where I think they should be working, but when I use the webmap ID for one in my organization, it just doesn't work.&amp;nbsp; It just sort of hangs on the loading of the map and asking for login credentials.&lt;/P&gt;&lt;P&gt;If I sub my webmap ID for the ID of the public ones that is in the esri samples, I get prompted for the login credentials and then everything loads up.&lt;/P&gt;&lt;P&gt;Is there maybe a setting on my webmap I need to adjust??&lt;/P&gt;&lt;P&gt;I have no clue why I can't get this to work.&amp;nbsp; Here is some code if it helps.&amp;nbsp; Line #64 is where I am seeing the hang.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;//   Copyright 2022 Esri
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//   https://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.

using System;
using System.Collections.Generic;
using System.Text;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Esri.ArcGISRuntime.Portal;

namespace AccessServicesWithOAuth
{

    class MapViewModel : INotifyPropertyChanged
    {
        public MapViewModel()
        {
            //SetupMap();
            _ = SetupMap();
        }

        public event PropertyChangedEventHandler? PropertyChanged;
        protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        private Map? _map;
        public Map? Map
        {
            get { return _map; }
            set
            {
                _map = value;
                OnPropertyChanged();
            }
        }

        private async Task SetupMap()
        {

            // Add the ArcGIS Online URL to the authentication helper.
            AuthenticationHelper.RegisterSecureServer("https://www.arcgis.com/sharing/rest");

            // Create a portal. If a URI is not specified, www.arcgis.com is used by default.
            ArcGISPortal portal = await ArcGISPortal.CreateAsync();

            // Get the portal item for a web map using its unique item id.
            PortalItem mapItem = await PortalItem.CreateAsync(portal, "41281c51f9de45edaf1c8ed44bb10e30");  //This is the esri sample ID
            
            //PortalItem mapItem = await PortalItem.CreateAsync(portal, "29ad2fc9b8794fb0b6dc1ca02948613d");    //This is the ID of my webmap.  If I change the sharing on this to 
                                                                                                              //"Everyone", then it loads up ok.  Only won't load up when you need 
                                                                                                              //to enter credentials.

            // Create the map from the item.
            Map map = new Map(mapItem);

            // Create a layer to display the ArcGIS World Traffic service.
            var trafficServiceUrl = "https://traffic.arcgis.com/arcgis/rest/services/World/Traffic/MapServer";
            var trafficLayer = new ArcGISMapImageLayer(new Uri(trafficServiceUrl));

            // Handle changes in the traffic layer's load status to check for errors.
            trafficLayer.LoadStatusChanged += TrafficLayer_LoadStatusChanged;

            // Add the traffic layer to the map's data layer collection.
            map.OperationalLayers.Add(trafficLayer);

            // To display the map, set the MapViewModel.Map property, which is bound to the map view.
            this.Map = map;

        }


        private void TrafficLayer_LoadStatusChanged(object? sender, Esri.ArcGISRuntime.LoadStatusEventArgs e)
        {
            // Report the error message if the traffic layer fails to load.
            if (e.Status == Esri.ArcGISRuntime.LoadStatus.FailedToLoad)
            {
                var trafficLayer = sender as ArcGISMapImageLayer;
                System.Windows.MessageBox.Show(trafficLayer?.LoadError?.Message, "Traffic layer did not load");
            }
        }

    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2023 15:47:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1338259#M12187</guid>
      <dc:creator>BrianBulla1</dc:creator>
      <dc:date>2023-10-16T15:47:43Z</dc:date>
    </item>
    <item>
      <title>Re: Help with OAuth</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1338270#M12188</link>
      <description>&lt;P&gt;Are you passing an API Key?&amp;nbsp; You need to pass in if using a public map.&amp;nbsp; You can do when loading map or in the Runtime Initialize&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2023 16:11:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1338270#M12188</guid>
      <dc:creator>JoeHershman</dc:creator>
      <dc:date>2023-10-16T16:11:19Z</dc:date>
    </item>
    <item>
      <title>Re: Help with OAuth</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1338287#M12189</link>
      <description>&lt;P&gt;Yes, I am passing my API key.&amp;nbsp; Do I need to do something in my Dev Account to link this API key directly to the webmap .... or some other kind of setting??&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BrianBulla1_0-1697474100085.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/83150i5177957ED2A46852/image-size/medium?v=v2&amp;amp;px=400" role="button" title="BrianBulla1_0-1697474100085.png" alt="BrianBulla1_0-1697474100085.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2023 16:35:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1338287#M12189</guid>
      <dc:creator>BrianBulla1</dc:creator>
      <dc:date>2023-10-16T16:35:08Z</dc:date>
    </item>
    <item>
      <title>Re: Help with OAuth</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1338301#M12191</link>
      <description>&lt;P&gt;Sorry...had to delete a post....still not working.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2023 17:09:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1338301#M12191</guid>
      <dc:creator>BrianBulla1</dc:creator>
      <dc:date>2023-10-16T17:09:41Z</dc:date>
    </item>
    <item>
      <title>Re: Help with OAuth</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1338302#M12192</link>
      <description>&lt;P&gt;You need to call ArcGISRuntime.Initialize after setting the API Key&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2023 17:11:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1338302#M12192</guid>
      <dc:creator>JoeHershman</dc:creator>
      <dc:date>2023-10-16T17:11:09Z</dc:date>
    </item>
    <item>
      <title>Re: Help with OAuth</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1338319#M12193</link>
      <description>&lt;P&gt;Thanks, but that didn't really maike any difference.&amp;nbsp; Still just a blank screen.&amp;nbsp; Seems like the only webmap I can get to work with login credentials is the esri sample one.&lt;/P&gt;&lt;P&gt;I have a regular AGOL account as well as an Organizational account, and trying to load up a webmap from either one where I would need to enter credentials just doesn't work.&amp;nbsp; Webmaps shared as "Everyone" seem to work fine.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2023 17:38:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1338319#M12193</guid>
      <dc:creator>BrianBulla1</dc:creator>
      <dc:date>2023-10-16T17:38:29Z</dc:date>
    </item>
    <item>
      <title>Re: Help with OAuth</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1338323#M12194</link>
      <description>&lt;P&gt;If you created an OAuth key through your developer account this would only be attached to your developer account.&amp;nbsp; Meaning it will only give you access to items stored on your developer AGOL.&amp;nbsp; An organizational account would require you to create a OAuth App in that Organization.&amp;nbsp; Have you tried to create a map in the AGOL site that is accessed by your developer login (I assume the BrianBulla1 named user) that you use to access the developer dashboard?&lt;/P&gt;&lt;P&gt;I have a developer site that came with my dev account, although I don't use.&amp;nbsp; But my company has an Organizational account.&amp;nbsp; An map that is setup in my Organization could not be accessed with an OAuth app I setup on the developer dashboard because it is a different account,&amp;nbsp; I could access the traffic layer with my dashboard OAuth&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2023 17:53:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1338323#M12194</guid>
      <dc:creator>JoeHershman</dc:creator>
      <dc:date>2023-10-16T17:53:17Z</dc:date>
    </item>
    <item>
      <title>Re: Help with OAuth</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1338326#M12195</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Yes, my testing has mainly be with useing the same dev. account and AGOL webmap.&lt;/P&gt;&lt;P&gt;Not quite sure how it's all setup, but with the esri samples, you need to add your own API key and OAuth details.&amp;nbsp; Those are both in my developer account, but in the samples all of the webmaps etc. that you access are esri resources, and everything seems to work using those ID's.&lt;/P&gt;&lt;P&gt;There must be something I'm missing....I just have no clue what it would be.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2023 17:58:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1338326#M12195</guid>
      <dc:creator>BrianBulla1</dc:creator>
      <dc:date>2023-10-16T17:58:20Z</dc:date>
    </item>
    <item>
      <title>Re: Help with OAuth</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1339678#M12198</link>
      <description>&lt;P&gt;If you successfully log in with OAuth, you don't need to provide an API key.&lt;/P&gt;&lt;P&gt;If it works for the map used in the sample but not for your map, perhaps the account you're logging in with does not have the expected access to that map. If you log in to ArcGIS Online with the same creds, can you access the web map?&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2023 17:06:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1339678#M12198</guid>
      <dc:creator>ThadTilton</dc:creator>
      <dc:date>2023-10-19T17:06:51Z</dc:date>
    </item>
    <item>
      <title>Re: Help with OAuth</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1340433#M12199</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/33463"&gt;@ThadTilton&lt;/a&gt;&amp;nbsp;.&amp;nbsp; As far as I'm aware, with the esri samples if you do not provide an API key they will not work.&amp;nbsp; There is a specific line of code/instructions that tells you to "insert API Key here".&lt;/P&gt;&lt;P&gt;As for my login, I can definitely see the webmap when I login online.&amp;nbsp; The map will also popup in my test app if I set the access level to "Everyone".&amp;nbsp; It only doesn't work if I set the access level to "Private".....which should generate the username/password screen, but instead the app just hangs there.&lt;/P&gt;&lt;P&gt;What's also weird is if I set my map to "Everyone" so that map actually loads, and then (in my code) add a layer that also needs authentication (esri World Traffic Service....just like in the sample), then I do get prompted for the username/password.&lt;/P&gt;&lt;P&gt;It only seems to hang when my own webmap needs authentication.&amp;nbsp; So this works when the webmap on line #12 is set to "Everyone", but as soon as I turn it back to "Private" everything hangs.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;        private async Task SetupMap()
        {

            // Add the ArcGIS Online URL to the authentication helper.
            AuthenticationHelper.RegisterSecureServer("https://www.arcgis.com/sharing/rest");

            // Create a portal. If a URI is not specified, www.arcgis.com is used by default.
            ArcGISPortal portal = await ArcGISPortal.CreateAsync();

            // Get the portal item for a web map using its unique item id.
            
            PortalItem mapItem = await PortalItem.CreateAsync(portal, "4f7b45cd7d034ea9a09ec58658bff70d");      //this is the ID of my AGOL webmap.  When set to "Everyone" it will load.

            // Create the map from the item.
            Map map = new Map(mapItem);

            // Create a layer to display the ArcGIS World Traffic service.
            var trafficServiceUrl = "https://traffic.arcgis.com/arcgis/rest/services/World/Traffic/MapServer";
            var trafficLayer = new ArcGISMapImageLayer(new Uri(trafficServiceUrl));

            // Handle changes in the traffic layer's load status to check for errors.
            trafficLayer.LoadStatusChanged += TrafficLayer_LoadStatusChanged;

            // Add the traffic layer to the map's data layer collection.
            map.OperationalLayers.Add(trafficLayer);

            // To display the map, set the MapViewModel.Map property, which is bound to the map view.
            this.Map = map;

        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2023 12:43:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1340433#M12199</guid>
      <dc:creator>BrianBulla1</dc:creator>
      <dc:date>2023-10-23T12:43:41Z</dc:date>
    </item>
    <item>
      <title>Re: Help with OAuth</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1340508#M12200</link>
      <description>&lt;P&gt;This does not register your OAuth app&lt;/P&gt;&lt;PRE&gt;AuthenticationHelper.RegisterSecureServer("https://www.arcgis.com/sharing/rest");&lt;/PRE&gt;&lt;P&gt;You need to register your OAuth.&amp;nbsp; The OAuthClientInfo is required&lt;/P&gt;&lt;PRE&gt;		ServerInfo serverInfo = new ServerInfo(serverUri)
		{
			TokenAuthenticationType = TokenAuthenticationType.OAuthAuthorizationCode,
			OAuthClientInfo = new OAuthClientInfo(AppClientId, redirectUri)
			{
				UserInterfaceStyle = UserInterfaceStyle.Dark,
				ClientSecret = ClientSecret,
			},

		};&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2023 15:06:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1340508#M12200</guid>
      <dc:creator>JoeHershman</dc:creator>
      <dc:date>2023-10-23T15:06:43Z</dc:date>
    </item>
    <item>
      <title>Re: Help with OAuth</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1340522#M12201</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/7529"&gt;@JoeHershman&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As per the sample, here is what .RegisterSecureServer is doing (part of the AuthenticationHelper.cs part of the project....not posted above).&amp;nbsp; The clientID and redirect Url are set earlier in the code and match what I have setup in the Developer dashboard.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public static void RegisterSecureServer(string url, 
                                        string clientID = OAuthClientID, 
                                        string redirectUrl = OAuthRedirectUrl)
{
    // Define the server URL, authentication type, client ID, and redirect URL.
    ServerInfo portalServerInfo = new ServerInfo(new Uri(url))
    {
        TokenAuthenticationType = TokenAuthenticationType.OAuthAuthorizationCode,
        OAuthClientInfo = new OAuthClientInfo(clientID, new Uri(redirectUrl))
    };

    // Register the server information with the AuthenticationManager.
    AuthenticationManager.Current.RegisterServer(portalServerInfo);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is more or less, what you suggested, but currently not working.&amp;nbsp; Not exactly sure how the redirect URL works, but I created exactly as the sample tutorial explained.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2023 15:27:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1340522#M12201</guid>
      <dc:creator>BrianBulla1</dc:creator>
      <dc:date>2023-10-23T15:27:52Z</dc:date>
    </item>
    <item>
      <title>Re: Help with OAuth</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1340677#M12205</link>
      <description>&lt;P&gt;I have exactly the same problem. I modified the sample to use a Feature Layer posted in our ArcGIS Online Organization. And everything works well. The login prompt appears when it hits that line:&lt;/P&gt;&lt;P&gt;PortalItem portalItem = await PortalItem.CreateAsync(arcgisPortal, WebMapId);&lt;/P&gt;&lt;P&gt;Then I created my own app. .Net 6, I do the register key, the&amp;nbsp;ArcGISLoginPrompt.SetChallengeHandler (I copied the whole class in my test project).. When I hit the same line, the login prompt does not appear but instead I get:&lt;/P&gt;&lt;P&gt;Esri.ArcGISRuntime.Http.ArcGISWebException: 'You do not have permissions to access this resource or perform this operation.'&lt;/P&gt;&lt;P&gt;The only thing different I can see are the projects that runs that code. Like in mine I can't add the nuget package&amp;nbsp;Esri.ArcGISRuntime.LocalServices. I don't know if it`s necessary.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I'm really looking forward to an explanation to this. I spent all day compararing ans searching a solution to that..&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2023 20:26:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1340677#M12205</guid>
      <dc:creator>PierreMasson</dc:creator>
      <dc:date>2023-10-23T20:26:30Z</dc:date>
    </item>
    <item>
      <title>Re: Help with OAuth</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1340685#M12206</link>
      <description>&lt;P&gt;Instead of having the app open it when it gets the PortalItem can you add&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;//THIS LINE SHOULD OPEN WINDOW!
var credential = await AuthenticationManager.Current.GenerateCredentialAsync(sharingUri);

AuthenticationManager.Current.AddCredential(credential);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;before&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;portal = await ArcGISPortal.CreateAsync(sharingUri);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;In your current code, if you put a breakpoint in the ChallangeHandler delegate does it get hit when you call (before making the change I describe above)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;PortalItem mapItem = await PortalItem.CreateAsync(portal, "29ad2fc9b8794fb0b6dc1ca02948613d");    //This is the ID of my webmap.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2023 20:40:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/help-with-oauth/m-p/1340685#M12206</guid>
      <dc:creator>JoeHershman</dc:creator>
      <dc:date>2023-10-23T20:40:13Z</dc:date>
    </item>
  </channel>
</rss>

