<?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: Creating a new Geodatabase object using ServiceConnectionProperties + username and password with a token-secured FeatureServer in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/creating-a-new-geodatabase-object-using/m-p/1302166#M9963</link>
    <description>&lt;P&gt;Rather buried in the documentation, I'm afraid, is the explanation for why this isnt working:&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic15000.html" target="_blank"&gt;https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic15000.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;the User and PWD properties are for use with legacy ArcGIS Server hosted services that are _not_ federated.&lt;/P&gt;&lt;P&gt;Instead, I think this is the pattern u r looking for:&lt;/P&gt;&lt;P&gt;ArcGIS.Core.System.Core.ArcGISSignOn:&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic25971.html" target="_blank"&gt;https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic25971.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Ideally u register a sign-on handler and resolve the credentials in your sign-on handler based on which service is calling u back (on your handler). However, if u know, upfront, that u r always calling just one service then u can bypass the callback handler pattern and just go against&amp;nbsp;ArcGIS.Core.System.Core.ArcGISSignOn.SignInWIthCredentials directly.&lt;/P&gt;&lt;P&gt;Here's what it would look like tho' there is a complete example here:&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic25964.html" target="_blank"&gt;https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic25964.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;No callback:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;//just call SignInwithCredentials directly....no call back:
var scp = new ServiceConnectionProperties(feature_service_uri);
//authenticate
string referer = "";
string token = "";
var ok = ArcGIS.Core.SystemCore.ArcGISSignOn.Instance.SignInWithCredentials(
				 portal_uri, user, superSecretPwd, out referer, out token);
//connect
using (var federatedFeatureService = new Geodatabase(scp)) {
   ...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With callback:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;internal class ChallengeHandler : ISignOnHandler {

  private void GetStoredUserNameAndPassword(
       string url, out string user, out string pwd) {
    user = "";
    pwd = "";
    if (url == "https://your_portal/portal/")
    {
       //TODO retrieve the relevant credentials
    }
    else if (url == "https://your_portal2/portal/")
    {
       //etc.
    }
  }

   //Call back when the service requires authentication
   public void GenerateCredentials(ref SIGNONHANDLERINFO info){

    string user = "";
    string superSecretPwd = "";

    GetStoredUserNameAndPassword(
          info.agoURL, out user, out superSecretPwd);

    //Authenticate
    var uri = new Uri(info.agoURL, UriKind.Absolute);
    string referer = "";
    string token = "";
    var ok = 
     ArcGIS.Core.SystemCore.ArcGISSignOn.Instance.SignInWithCredentials(
    	 uri, user, superSecretPwd, out referer, out token);
    if (ok) {
    	//TODO: for example, if you want to retain the token and referer
    	//for your own purposes that code would go here...
    }
  }
}

 //elsewhere - in your console Main(...)
 //Set your challenge handler...
 ArcGIS.Core.SystemCore.ArcGISSignOn.Instance.SetSignonHandler(new ChallengeHandler());

 var scp = new ServiceConnectionProperties(feature_service_uri);

 //connect - if authentication is required, your callback will be invoked...
 using (var federatedFeatureService = new Geodatabase(scp)) {
   ...&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;&amp;nbsp;&lt;/P&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;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 22 Jun 2023 18:36:51 GMT</pubDate>
    <dc:creator>CharlesMacleod</dc:creator>
    <dc:date>2023-06-22T18:36:51Z</dc:date>
    <item>
      <title>Creating a new Geodatabase object using ServiceConnectionProperties + username and password with a token-secured FeatureServer</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/creating-a-new-geodatabase-object-using/m-p/1301057#M9949</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ThomasRea_0-1687269578471.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/73695iE31635445B5B6842/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ThomasRea_0-1687269578471.png" alt="ThomasRea_0-1687269578471.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My requirements are pretty straightforward. WE have an AGO hosted feature server that is token secured, but I need to create a direct geodatabase connection using the .NET SDK via a Core Host application (note: this code works just fine through an add-in context). However, I'm getting the following error:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;ArcGIS.Core.Data.GeodatabaseNotFoundOrOpenedException: Cannot find or open the specified geodatabase or data store. ---&amp;gt; ArcGIS.Core.Data.ServiceException: Authentication token required. ---&amp;gt; System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x8004021A&lt;BR /&gt;&lt;BR /&gt;Which is strange, because I'm supplying the username and password. The SDK offers no way to set the Token. Also, even stranger, is that when I use the same code to create a connection to the same service from within an add-in, the username and password are not used, and the connection works. I'm guessing it's because the COM call is already authenticated since pro is open and I am logged in with my AGO credentials already. Any ideas?&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2023 14:03:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/creating-a-new-geodatabase-object-using/m-p/1301057#M9949</guid>
      <dc:creator>ThomasRea</dc:creator>
      <dc:date>2023-06-20T14:03:04Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new Geodatabase object using ServiceConnectionProperties + username and password with a token-secured FeatureServer</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/creating-a-new-geodatabase-object-using/m-p/1302166#M9963</link>
      <description>&lt;P&gt;Rather buried in the documentation, I'm afraid, is the explanation for why this isnt working:&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic15000.html" target="_blank"&gt;https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic15000.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;the User and PWD properties are for use with legacy ArcGIS Server hosted services that are _not_ federated.&lt;/P&gt;&lt;P&gt;Instead, I think this is the pattern u r looking for:&lt;/P&gt;&lt;P&gt;ArcGIS.Core.System.Core.ArcGISSignOn:&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic25971.html" target="_blank"&gt;https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic25971.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Ideally u register a sign-on handler and resolve the credentials in your sign-on handler based on which service is calling u back (on your handler). However, if u know, upfront, that u r always calling just one service then u can bypass the callback handler pattern and just go against&amp;nbsp;ArcGIS.Core.System.Core.ArcGISSignOn.SignInWIthCredentials directly.&lt;/P&gt;&lt;P&gt;Here's what it would look like tho' there is a complete example here:&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic25964.html" target="_blank"&gt;https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic25964.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;No callback:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;//just call SignInwithCredentials directly....no call back:
var scp = new ServiceConnectionProperties(feature_service_uri);
//authenticate
string referer = "";
string token = "";
var ok = ArcGIS.Core.SystemCore.ArcGISSignOn.Instance.SignInWithCredentials(
				 portal_uri, user, superSecretPwd, out referer, out token);
//connect
using (var federatedFeatureService = new Geodatabase(scp)) {
   ...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With callback:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;internal class ChallengeHandler : ISignOnHandler {

  private void GetStoredUserNameAndPassword(
       string url, out string user, out string pwd) {
    user = "";
    pwd = "";
    if (url == "https://your_portal/portal/")
    {
       //TODO retrieve the relevant credentials
    }
    else if (url == "https://your_portal2/portal/")
    {
       //etc.
    }
  }

   //Call back when the service requires authentication
   public void GenerateCredentials(ref SIGNONHANDLERINFO info){

    string user = "";
    string superSecretPwd = "";

    GetStoredUserNameAndPassword(
          info.agoURL, out user, out superSecretPwd);

    //Authenticate
    var uri = new Uri(info.agoURL, UriKind.Absolute);
    string referer = "";
    string token = "";
    var ok = 
     ArcGIS.Core.SystemCore.ArcGISSignOn.Instance.SignInWithCredentials(
    	 uri, user, superSecretPwd, out referer, out token);
    if (ok) {
    	//TODO: for example, if you want to retain the token and referer
    	//for your own purposes that code would go here...
    }
  }
}

 //elsewhere - in your console Main(...)
 //Set your challenge handler...
 ArcGIS.Core.SystemCore.ArcGISSignOn.Instance.SetSignonHandler(new ChallengeHandler());

 var scp = new ServiceConnectionProperties(feature_service_uri);

 //connect - if authentication is required, your callback will be invoked...
 using (var federatedFeatureService = new Geodatabase(scp)) {
   ...&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;&amp;nbsp;&lt;/P&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2023 18:36:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/creating-a-new-geodatabase-object-using/m-p/1302166#M9963</guid>
      <dc:creator>CharlesMacleod</dc:creator>
      <dc:date>2023-06-22T18:36:51Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new Geodatabase object using ServiceConnectionProperties + username and password with a token-secured FeatureServer</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/creating-a-new-geodatabase-object-using/m-p/1302439#M9972</link>
      <description>&lt;P&gt;Thank you! Ultimately, that's the conclusion I came too as well after discussing with ESRI support. Unfortunately, though, the ISignOnHandler.GenerateCredentials doesn't seem to be called by the Geodatabase constructor (I get the same exception as before). When I do it explicitly by directly calling&amp;nbsp;ArcGISSignOn.Instance.SignInWithCredentials, it does work, but then I'm encountering unexpected caching behavior, so this solution also isn't ideal for me. The ideal scenario is that GenerateCredentials would not cache tokens between processes/executions and would expose some way to revoke a token after execution. However, the&amp;nbsp;ArcGISSignOn.Instance.SignOut doesn't seem to work as expected, because follow-up executions remain authenticated, even after calling this method. Very strange.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2023 13:45:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/creating-a-new-geodatabase-object-using/m-p/1302439#M9972</guid>
      <dc:creator>ThomasRea</dc:creator>
      <dc:date>2023-06-23T13:45:30Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new Geodatabase object using ServiceConnectionProperties + username and password with a token-secured FeatureServer</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/creating-a-new-geodatabase-object-using/m-p/1302543#M9973</link>
      <description>&lt;P&gt;It is probably related to this:&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/help/projects/sign-in-to-your-organization.htm" target="_blank" rel="noopener"&gt;https://pro.arcgis.com/en/pro-app/latest/help/projects/sign-in-to-your-organization.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;note option 3:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Check&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class=""&gt;Sign in automatically&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;to have&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class=""&gt;ArcGIS Pro&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;store your credentials and sign in to the portal automatically; this option is checked by default.&lt;/LI&gt;&lt;LI&gt;Uncheck&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class=""&gt;Sign in automatically&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;if you prefer to provide your credentials each time you start&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class=""&gt;ArcGIS Pro&lt;/SPAN&gt;.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2023 17:05:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/creating-a-new-geodatabase-object-using/m-p/1302543#M9973</guid>
      <dc:creator>CharlesMacleod</dc:creator>
      <dc:date>2023-06-23T17:05:03Z</dc:date>
    </item>
  </channel>
</rss>

