<?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>idea ArcGISPortal.CreateAsync should trigger ChallengeHandler in ArcGIS Maps SDKs Native Ideas</title>
    <link>https://community.esri.com/t5/arcgis-maps-sdks-native-ideas/arcgisportal-createasync-should-trigger/idi-p/1202444</link>
    <description>&lt;P&gt;The best practice is to use&amp;nbsp;AuthenticationManager.Current.ChallengeHandler to generate credentials and update&amp;nbsp;AuthenticationManager credential store.&amp;nbsp; The previous approach of calling ArcGISPortal.CreateAsync and passing a credential has been marked as obsolete.&lt;/P&gt;&lt;P&gt;This allows one to create a ArcGISPortal object which is not initialized.&amp;nbsp; I am unclear what value this object would serve and why the&amp;nbsp;ArcGISPortal.CreateAsync does not fire the&amp;nbsp;ChallengeHandler .&lt;/P&gt;&lt;P&gt;Currently in order to get a initialized&amp;nbsp;ArcGISPortal there would be a couple approaches&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;//Launches OAuth dialog, but does not fire ChallengeHandler
var credential = await AuthenticationManager.Current.GenerateCredentialAsync(new Uri(ServerUrl));
AuthenticationManager.Current.AddCredential(credential);

//ArcGIS Portal object that is hydrated
_portal = await ArcGISPortal.CreateAsync(new Uri(ServerUrl));&lt;/LI-CODE&gt;&lt;P&gt;The other approach would be&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;//Create ArcGISPortal without a User object
_portal = await ArcGISPortal.CreateAsync(new Uri(ServerUrl));

// this will trigger the ChallengeHandler which launches OAuth dialog 
_= await PortalItem.CreateAsync(_portal, "eb8be7257df742baaf320158b16f676b");

//run CreateAsync another time to get the hydrated ArcGISPortal object
_portal = await ArcGISPortal.CreateAsync(new Uri(ServerUrl));&lt;/LI-CODE&gt;&lt;P&gt;The first approach seems better and it is not hard to hide the details in an your own OpenPortal method.&amp;nbsp;&lt;/P&gt;&lt;P&gt;It seems to me to defeat the point of the&amp;nbsp;&amp;nbsp;AuthenticationManager. and ChallengeHandler &amp;nbsp;pattern.&amp;nbsp; To encapsulate the GenerateCredential code in the single ChallengeHandler delegate, the latter approach would be required, and one calls&amp;nbsp;CreateAsync twice.&amp;nbsp; Or one could use the former approach, but then are not even using the&amp;nbsp;&amp;nbsp;ChallengeHandler.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Seems that&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;_portal = await ArcGISPortal.CreateAsync(new Uri(ServerUrl));&lt;/LI-CODE&gt;&lt;P&gt;triggering the&amp;nbsp;&amp;nbsp;ChallengeHandler would be better.&amp;nbsp; As the&amp;nbsp;ArcGISPortal object is somewhat useless until authentication has occurred&lt;/P&gt;</description>
    <pubDate>Fri, 12 Aug 2022 16:06:08 GMT</pubDate>
    <dc:creator>JoeHershman</dc:creator>
    <dc:date>2022-08-12T16:06:08Z</dc:date>
    <item>
      <title>ArcGISPortal.CreateAsync should trigger ChallengeHandler</title>
      <link>https://community.esri.com/t5/arcgis-maps-sdks-native-ideas/arcgisportal-createasync-should-trigger/idi-p/1202444</link>
      <description>&lt;P&gt;The best practice is to use&amp;nbsp;AuthenticationManager.Current.ChallengeHandler to generate credentials and update&amp;nbsp;AuthenticationManager credential store.&amp;nbsp; The previous approach of calling ArcGISPortal.CreateAsync and passing a credential has been marked as obsolete.&lt;/P&gt;&lt;P&gt;This allows one to create a ArcGISPortal object which is not initialized.&amp;nbsp; I am unclear what value this object would serve and why the&amp;nbsp;ArcGISPortal.CreateAsync does not fire the&amp;nbsp;ChallengeHandler .&lt;/P&gt;&lt;P&gt;Currently in order to get a initialized&amp;nbsp;ArcGISPortal there would be a couple approaches&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;//Launches OAuth dialog, but does not fire ChallengeHandler
var credential = await AuthenticationManager.Current.GenerateCredentialAsync(new Uri(ServerUrl));
AuthenticationManager.Current.AddCredential(credential);

//ArcGIS Portal object that is hydrated
_portal = await ArcGISPortal.CreateAsync(new Uri(ServerUrl));&lt;/LI-CODE&gt;&lt;P&gt;The other approach would be&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;//Create ArcGISPortal without a User object
_portal = await ArcGISPortal.CreateAsync(new Uri(ServerUrl));

// this will trigger the ChallengeHandler which launches OAuth dialog 
_= await PortalItem.CreateAsync(_portal, "eb8be7257df742baaf320158b16f676b");

//run CreateAsync another time to get the hydrated ArcGISPortal object
_portal = await ArcGISPortal.CreateAsync(new Uri(ServerUrl));&lt;/LI-CODE&gt;&lt;P&gt;The first approach seems better and it is not hard to hide the details in an your own OpenPortal method.&amp;nbsp;&lt;/P&gt;&lt;P&gt;It seems to me to defeat the point of the&amp;nbsp;&amp;nbsp;AuthenticationManager. and ChallengeHandler &amp;nbsp;pattern.&amp;nbsp; To encapsulate the GenerateCredential code in the single ChallengeHandler delegate, the latter approach would be required, and one calls&amp;nbsp;CreateAsync twice.&amp;nbsp; Or one could use the former approach, but then are not even using the&amp;nbsp;&amp;nbsp;ChallengeHandler.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Seems that&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;_portal = await ArcGISPortal.CreateAsync(new Uri(ServerUrl));&lt;/LI-CODE&gt;&lt;P&gt;triggering the&amp;nbsp;&amp;nbsp;ChallengeHandler would be better.&amp;nbsp; As the&amp;nbsp;ArcGISPortal object is somewhat useless until authentication has occurred&lt;/P&gt;</description>
      <pubDate>Fri, 12 Aug 2022 16:06:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-maps-sdks-native-ideas/arcgisportal-createasync-should-trigger/idi-p/1202444</guid>
      <dc:creator>JoeHershman</dc:creator>
      <dc:date>2022-08-12T16:06:08Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGISPortal.CreateAsync should trigger ChallengeHandler</title>
      <link>https://community.esri.com/t5/arcgis-maps-sdks-native-ideas/arcgisportal-createasync-should-trigger/idc-p/1312235#M243</link>
      <description>&lt;P&gt;Thank you.&amp;nbsp; Exactly what I was looking for.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2023 19:00:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-maps-sdks-native-ideas/arcgisportal-createasync-should-trigger/idc-p/1312235#M243</guid>
      <dc:creator>RN1</dc:creator>
      <dc:date>2023-07-26T19:00:46Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGISPortal.CreateAsync should trigger ChallengeHandler</title>
      <link>https://community.esri.com/t5/arcgis-maps-sdks-native-ideas/arcgisportal-createasync-should-trigger/idc-p/1600300#M271</link>
      <description>&lt;P&gt;ArcGISPortal.CreateAsync will not issue a challenge only if a portal allows anonymous access. It may still be useful if you are only browsing publicly-accessible content.&lt;/P&gt;&lt;P&gt;But there is a way to force login even when anonymous access is possible.&amp;nbsp; ArcGISPortal.CreateAsync has an overload that takes a boolean "loginRequired" parameter. When set to "true", portal will always check for a usable credential and call the ChallengeHandler if needed.&lt;/P&gt;&lt;P&gt;I hope this fits your needs!&lt;/P&gt;</description>
      <pubDate>Fri, 28 Mar 2025 05:56:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-maps-sdks-native-ideas/arcgisportal-createasync-should-trigger/idc-p/1600300#M271</guid>
      <dc:creator>MatveiStefarov</dc:creator>
      <dc:date>2025-03-28T05:56:07Z</dc:date>
    </item>
  </channel>
</rss>

