<?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 Access protected feature service with the Maps SDK in .NET Maps SDK Questions</title>
    <link>https://community.esri.com/t5/net-maps-sdk-questions/access-protected-feature-service-with-the-maps-sdk/m-p/1325798#M12084</link>
    <description>&lt;P&gt;I'm trying to access a protected feature service using the Maps SDK version 200.2, and would like to use an application login to do so.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My basic flow so far is this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;AuthenticationManager.Current.ChallengeHandler = new AppChallengeHandler();
      
var table = new ServiceFeatureTable(new Uri("https://example.com/arcgis/rest/services/Test/FeatureServer/0"));
await table.LoadAsync();&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;internal class AppChallengeHandler : IChallengeHandler
{
    public async Task&amp;lt;Credential&amp;gt; CreateCredentialAsync(CredentialRequestInfo requestInfo)
    {
        var challengeRequest = new CredentialRequestInfo
        {
            GenerateTokenOptions = new GenerateTokenOptions
            {
                TokenAuthenticationType = TokenAuthenticationType.OAuthClientCredentials,
            },
            ServiceUri = new Uri("https://example.com/portal"),
        };

        var serverInfo = AuthenticationManager.Current.FindServerInfo(
            new Uri("https://example.com/arcgis/rest"));
        serverInfo.OAuthClientInfo = new OAuthClientInfo(
            CLIENTID,
            new Uri("https://example.com"),
            CLIENTSECRET);
        serverInfo.TokenAuthenticationType = TokenAuthenticationType.OAuthClientCredentials;

        var creds = await AuthenticationManager.Current.GetCredentialAsync(challengeRequest, false);
        if (creds == null)
        {
            throw new Exception("Not authorized");
        }

        return creds;
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The call to LoadAsync triggers CreateCredentialsAsync, at which time a serverInfo object for the service is added to the AuthenticationManager.&lt;/P&gt;&lt;P&gt;However, the code just stops at GetCredentialsAsync, no exception, nothing in the output window of Visual Studio, no request to be seen in Fiddler.&lt;/P&gt;&lt;P&gt;Does anyone know how to do this?&lt;/P&gt;</description>
    <pubDate>Wed, 06 Sep 2023 10:59:17 GMT</pubDate>
    <dc:creator>BerendVeldkamp</dc:creator>
    <dc:date>2023-09-06T10:59:17Z</dc:date>
    <item>
      <title>Access protected feature service with the Maps SDK</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/access-protected-feature-service-with-the-maps-sdk/m-p/1325798#M12084</link>
      <description>&lt;P&gt;I'm trying to access a protected feature service using the Maps SDK version 200.2, and would like to use an application login to do so.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My basic flow so far is this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;AuthenticationManager.Current.ChallengeHandler = new AppChallengeHandler();
      
var table = new ServiceFeatureTable(new Uri("https://example.com/arcgis/rest/services/Test/FeatureServer/0"));
await table.LoadAsync();&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;internal class AppChallengeHandler : IChallengeHandler
{
    public async Task&amp;lt;Credential&amp;gt; CreateCredentialAsync(CredentialRequestInfo requestInfo)
    {
        var challengeRequest = new CredentialRequestInfo
        {
            GenerateTokenOptions = new GenerateTokenOptions
            {
                TokenAuthenticationType = TokenAuthenticationType.OAuthClientCredentials,
            },
            ServiceUri = new Uri("https://example.com/portal"),
        };

        var serverInfo = AuthenticationManager.Current.FindServerInfo(
            new Uri("https://example.com/arcgis/rest"));
        serverInfo.OAuthClientInfo = new OAuthClientInfo(
            CLIENTID,
            new Uri("https://example.com"),
            CLIENTSECRET);
        serverInfo.TokenAuthenticationType = TokenAuthenticationType.OAuthClientCredentials;

        var creds = await AuthenticationManager.Current.GetCredentialAsync(challengeRequest, false);
        if (creds == null)
        {
            throw new Exception("Not authorized");
        }

        return creds;
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The call to LoadAsync triggers CreateCredentialsAsync, at which time a serverInfo object for the service is added to the AuthenticationManager.&lt;/P&gt;&lt;P&gt;However, the code just stops at GetCredentialsAsync, no exception, nothing in the output window of Visual Studio, no request to be seen in Fiddler.&lt;/P&gt;&lt;P&gt;Does anyone know how to do this?&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2023 10:59:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/access-protected-feature-service-with-the-maps-sdk/m-p/1325798#M12084</guid>
      <dc:creator>BerendVeldkamp</dc:creator>
      <dc:date>2023-09-06T10:59:17Z</dc:date>
    </item>
    <item>
      <title>Re: Access protected feature service with the Maps SDK</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/access-protected-feature-service-with-the-maps-sdk/m-p/1325813#M12085</link>
      <description>&lt;P&gt;Have you tried&amp;nbsp;&lt;A href="https://developers.arcgis.com/net/api-reference/api/net/Esri.ArcGISRuntime/Esri.ArcGISRuntime.Security.AuthenticationManager.GenerateCredentialAsync.html#Esri_ArcGISRuntime_Security_AuthenticationManager_GenerateCredentialAsync_System_Uri_Esri_ArcGISRuntime_Security_GenerateTokenOptions_" target="_blank" rel="noopener"&gt;Method GenerateCredentialAsync (arcgis.com)&lt;/A&gt;&amp;nbsp;rather than&amp;nbsp;&lt;A href="https://developers.arcgis.com/net/api-reference/api/net/Esri.ArcGISRuntime/Esri.ArcGISRuntime.Security.AuthenticationManager.GetCredentialAsync.html#Esri_ArcGISRuntime_Security_AuthenticationManager_GetCredentialAsync_Esri_ArcGISRuntime_Security_CredentialRequestInfo_System_Boolean_" target="_blank" rel="noopener"&gt;Method GetCredentialAsync (arcgis.com)&lt;/A&gt;?&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wonder if it never returns because it's stuck in a loop (Get will raise the Challenge, which will call Get, etc)?&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2023 12:10:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/access-protected-feature-service-with-the-maps-sdk/m-p/1325813#M12085</guid>
      <dc:creator>MichaelBranscomb</dc:creator>
      <dc:date>2023-09-06T12:10:20Z</dc:date>
    </item>
    <item>
      <title>Re: Access protected feature service with the Maps SDK</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/access-protected-feature-service-with-the-maps-sdk/m-p/1325828#M12086</link>
      <description>&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;I replaced that line with&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var creds = await AuthenticationManager.Current.GenerateCredentialAsync(
    new Uri("https://example.com/portal"), 
    challengeRequest.GenerateTokenOptions);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But now the program throws an exception '&lt;EM&gt;OAuth-Client-id must be set before trying to generate an OAuth token&lt;/EM&gt;'.&lt;/P&gt;&lt;P&gt;I think this is because the runtime is trying to lookup a serverInfo for the /portal URL rather than /arcgis. After adding a new serverinfo for /portal with the same clientid and secret to the AuthenticationManager, GenerateCredentials works, but it returns a credentials object for /portal, not /arcgis.&lt;/P&gt;&lt;P&gt;I also tried to return a new Credentials object for the correct /arcgis URl, but that doesn't seem to be accepted either.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;//return creds;
return new OAuthTokenCredential(new Uri("https://example.com/arcgis/rest"), creds.Token)
{
    ExpirationDate = creds.ExpirationDate,
    GenerateTokenOptions = creds.GenerateTokenOptions
};&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My CreateCredentialAsync method is called three times, before finally giving up.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2023 12:59:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/access-protected-feature-service-with-the-maps-sdk/m-p/1325828#M12086</guid>
      <dc:creator>BerendVeldkamp</dc:creator>
      <dc:date>2023-09-06T12:59:29Z</dc:date>
    </item>
  </channel>
</rss>

