Can I get a sample code for authorizing a runtime user against ArcGIS.COM? I like to have my own dialog box (not the default ESRI one) that prompts the user for named user login.
Don't really have a way to package up a working sample but basically have a View that has the Text boxes and a button to launch command. When that executes you create a Credential using the passed in username and password.
Below is a ViewModel bound to the view (this is in Xamarin not WPF - and also uses Prism Framework). LoginCommand is bound to the button. Basically checks to make sure the user entered the username and password and then tries to connect using the IPortalManager service - Code below).
<SPAN class="keyword token">public</SPAN> <SPAN class="keyword token">class</SPAN> <SPAN class="token class-name">LoginPopupPageViewModel</SPAN> <SPAN class="punctuation token">:</SPAN> ViewModelBase <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">private</SPAN> <SPAN class="keyword token">readonly</SPAN> IPageDialogService _pageDialogService<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">private</SPAN> <SPAN class="keyword token">readonly</SPAN> IPortalManager _portalManager<SPAN class="punctuation token">;</SPAN> <SPAN class="token preprocessor">#region Private Backing Fields</SPAN> <SPAN class="keyword token">private</SPAN> <SPAN class="keyword token">string</SPAN> _userName<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">private</SPAN> <SPAN class="keyword token">string</SPAN> _password<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">private</SPAN> <SPAN class="keyword token">bool</SPAN> _useDevAgol<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">private</SPAN> <SPAN class="keyword token">string</SPAN> _navigateToPage<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">private</SPAN> <SPAN class="keyword token">string</SPAN> _message<SPAN class="punctuation token">;</SPAN> <SPAN class="token preprocessor">#endregion</SPAN> <SPAN class="keyword token">public</SPAN> <SPAN class="token function">LoginPopupPageViewModel</SPAN><SPAN class="punctuation token">(</SPAN>IPageDialogService pageDialogService<SPAN class="punctuation token">,</SPAN> IPortalManager portalManager<SPAN class="punctuation token">,</SPAN> IEventAggregator eventAggregator<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">base</SPAN><SPAN class="punctuation token">(</SPAN>eventAggregator<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> _pageDialogService <SPAN class="operator token">=</SPAN> pageDialogService<SPAN class="punctuation token">;</SPAN> _portalManager <SPAN class="operator token">=</SPAN> portalManager<SPAN class="punctuation token">;</SPAN> Title <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Peoples As-Built"</SPAN><SPAN class="punctuation token">;</SPAN> _useDevAgol <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">false</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="token preprocessor">#region Bound Properties</SPAN> <SPAN class="keyword token">public</SPAN> <SPAN class="keyword token">bool</SPAN> UseDevAgol <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">get</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> _useDevAgol<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">set</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> <SPAN class="token function">SetProperty</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">ref</SPAN> _useDevAgol<SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">value</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">public</SPAN> <SPAN class="keyword token">string</SPAN> UserName <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">get</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> _userName<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">set</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> <SPAN class="token function">SetProperty</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">ref</SPAN> _userName<SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">value</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">public</SPAN> <SPAN class="keyword token">string</SPAN> Password <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">get</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> _password<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">set</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> <SPAN class="token function">SetProperty</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">ref</SPAN> _password<SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">value</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">public</SPAN> <SPAN class="keyword token">string</SPAN> Message <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">get</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> _message<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">set</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> <SPAN class="token function">SetProperty</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">ref</SPAN> _message<SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">value</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="token preprocessor">#endregion</SPAN> <SPAN class="token preprocessor">#region LoginCommand</SPAN> <SPAN class="keyword token">public</SPAN> DelegateCommand LoginCommand <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">DelegateCommand</SPAN><SPAN class="punctuation token">(</SPAN>ExecuteLogin<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">public</SPAN> <SPAN class="keyword token">async</SPAN> <SPAN class="keyword token">void</SPAN> <SPAN class="token function">ExecuteLogin</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">try</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>UserName <SPAN class="operator token">==</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">await</SPAN> _pageDialogService<SPAN class="punctuation token">.</SPAN><SPAN class="token function">DisplayAlertAsync</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"User Name"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"You need to enter a User Name"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Close"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">return</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>Password <SPAN class="operator token">==</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">await</SPAN> _pageDialogService<SPAN class="punctuation token">.</SPAN><SPAN class="token function">DisplayAlertAsync</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Password"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"You need to enter a Password"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Close"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">return</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> Settings<SPAN class="punctuation token">.</SPAN>UserName <SPAN class="operator token">=</SPAN> UserName<SPAN class="punctuation token">;</SPAN> Settings<SPAN class="punctuation token">.</SPAN>Password <SPAN class="operator token">=</SPAN> Password<SPAN class="punctuation token">;</SPAN> Settings<SPAN class="punctuation token">.</SPAN>UseDevAgol <SPAN class="operator token">=</SPAN> UseDevAgol<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">await</SPAN> NavigationService<SPAN class="punctuation token">.</SPAN><SPAN class="token function">NavigateAsync</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"BusyPopupPage"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">NavigationParameters</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"?message=Logging into ArcGIS Online"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//TODO: Check for connection - See Xamarin Essentials</SPAN> <SPAN class="keyword token">await</SPAN> _portalManager<SPAN class="punctuation token">.</SPAN><SPAN class="token function">OpenPortalAsync</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">await</SPAN> NavigationService<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GoBackAsync</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">NavigationParameters</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"?source=busy"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN> _portalManager<SPAN class="punctuation token">.</SPAN>ConnectionStatus <SPAN class="operator token">==</SPAN> ConnectionStatus<SPAN class="punctuation token">.</SPAN>InvalidUser <SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">await</SPAN> _pageDialogService<SPAN class="punctuation token">.</SPAN><SPAN class="token function">DisplayAlertAsync</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Login failed"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Login failed. Please retry"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Close"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> UserName <SPAN class="operator token">=</SPAN> Password <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">return</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="comment token">// Integrated this so that we can direct to different end destinations after login</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>_navigateToPage <SPAN class="operator token">!=</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">await</SPAN> NavigationService<SPAN class="punctuation token">.</SPAN><SPAN class="token function">NavigateAsync</SPAN><SPAN class="punctuation token">(</SPAN>_navigateToPage<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">else</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="comment token">//return to calling page</SPAN> <SPAN class="keyword token">await</SPAN> NavigationService<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GoBackAsync</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">catch</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="token class-name">Exception</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">await</SPAN> _pageDialogService<SPAN class="punctuation token">.</SPAN><SPAN class="token function">DisplayAlertAsync</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Login failed"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Login failed. Please retry"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Close"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="token preprocessor">#endregion</SPAN> <SPAN class="token preprocessor">#region CancelCommand</SPAN> <SPAN class="keyword token">public</SPAN> ICommand CancelCommand <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">DelegateCommand</SPAN><SPAN class="operator token"><</SPAN><SPAN class="keyword token">object</SPAN><SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN>ExecuteCancel<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">private</SPAN> <SPAN class="keyword token">async</SPAN> <SPAN class="keyword token">void</SPAN> <SPAN class="token function">ExecuteCancel</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">object</SPAN> obj<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">await</SPAN> NavigationService<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GoBackAsync</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="token preprocessor">#endregion</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
PortalManager: One of the things that is needed is in the AuthenticationManager.Current.GenerateCredentialAsync method you need to use the sharing Url = https://arcgis.com/sharing/rest
<SPAN class="keyword token">public</SPAN> <SPAN class="keyword token">class</SPAN> <SPAN class="token class-name">PortalManager</SPAN> <SPAN class="punctuation token">:</SPAN> IPortalManager <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">private</SPAN> ArcGISPortal _portal<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">private</SPAN> TokenCredential _credential<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">private</SPAN> <SPAN class="keyword token">readonly</SPAN> ILogger _log<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">public</SPAN> <SPAN class="token function">PortalManager</SPAN><SPAN class="punctuation token">(</SPAN>ILogManager logManager<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> _log <SPAN class="operator token">=</SPAN> logManager<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetLog</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> ConnectionStatus <SPAN class="operator token">=</SPAN> ConnectionStatus<SPAN class="punctuation token">.</SPAN>NotConnected<SPAN class="punctuation token">;</SPAN> PortalUser <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">public</SPAN> <SPAN class="keyword token">async</SPAN> Task<SPAN class="operator token"><</SPAN>ArcGISPortal<SPAN class="operator token">></SPAN> <SPAN class="token function">OpenPortalAsync</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">bool</SPAN> refresh <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">false</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>_portal <SPAN class="operator token">!=</SPAN> <SPAN class="keyword token">null</SPAN> <SPAN class="operator token">&&</SPAN> <SPAN class="operator token">!</SPAN>refresh<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">return</SPAN> _portal<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">try</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">var</SPAN> credential <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">await</SPAN> <SPAN class="token function">Credential</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">true</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//public static Uri AgolUrl => new Uri("https://arcgis.com");</SPAN> _portal <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">await</SPAN> ArcGISPortal<SPAN class="punctuation token">.</SPAN><SPAN class="token function">CreateAsync</SPAN><SPAN class="punctuation token">(</SPAN>Constants<SPAN class="punctuation token">.</SPAN>AgolUrl<SPAN class="punctuation token">,</SPAN> credential<SPAN class="punctuation token">,</SPAN> CancellationToken<SPAN class="punctuation token">.</SPAN>None<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> ConnectionStatus <SPAN class="operator token">=</SPAN> ConnectionStatus<SPAN class="punctuation token">.</SPAN>Connected<SPAN class="punctuation token">;</SPAN> PortalUser <SPAN class="operator token">=</SPAN> _portal<SPAN class="punctuation token">.</SPAN>User<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">return</SPAN> _portal<SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">catch</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="token class-name">ArcGISWebException</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> ConnectionStatus <SPAN class="operator token">=</SPAN> ConnectionStatus<SPAN class="punctuation token">.</SPAN>InvalidUser<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">return</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">catch</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="token class-name">InvalidOperationException</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> ConnectionStatus <SPAN class="operator token">=</SPAN> ConnectionStatus<SPAN class="punctuation token">.</SPAN>UnableToConnect<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">return</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">catch</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="token class-name">Exception</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> ConnectionStatus <SPAN class="operator token">=</SPAN> ConnectionStatus<SPAN class="punctuation token">.</SPAN>UnableToConnect<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">return</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">public</SPAN> <SPAN class="keyword token">async</SPAN> Task<SPAN class="operator token"><</SPAN>TokenCredential<SPAN class="operator token">></SPAN> <SPAN class="token function">Credential</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">bool</SPAN> refresh<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>_credential <SPAN class="operator token">!=</SPAN> <SPAN class="keyword token">null</SPAN> <SPAN class="operator token">&&</SPAN> <SPAN class="operator token">!</SPAN>refresh<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">return</SPAN> _credential<SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// public static Uri AgolSharingUri = new Uri("https://arcgis.com/sharing/rest");</SPAN> _credential <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">await</SPAN> AuthenticationManager<SPAN class="punctuation token">.</SPAN>Current<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GenerateCredentialAsync</SPAN><SPAN class="punctuation token">(</SPAN>Constants<SPAN class="punctuation token">.</SPAN>AgolSharingUri<SPAN class="punctuation token">,</SPAN> Settings<SPAN class="punctuation token">.</SPAN>UserName<SPAN class="punctuation token">,</SPAN> Settings<SPAN class="punctuation token">.</SPAN>Password<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">return</SPAN> _credential<SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">public</SPAN> <SPAN class="keyword token">void</SPAN> <SPAN class="token function">SignOut</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> _portal <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">;</SPAN> _credential <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">;</SPAN> PortalUser <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">public</SPAN> ConnectionStatus ConnectionStatus <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">get</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">private</SPAN> <SPAN class="keyword token">set</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">public</SPAN> PortalUser PortalUser <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">get</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">private</SPAN> <SPAN class="keyword token">set</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Hope that helps
-Joe
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.