title: System.InvalidOperationException: IDX20803: Unable to obtain configuration from (OKTA)
body: <p>I'm trying to implement the <code>Okta.AspNetCore</code> middleware based on their docs on their GitHub page <a href="https://github.com/okta/okta-aspnet/blob/master/docs/aspnetcore-webapi.md" rel="nofollow noreferrer">https://github.com/okta/okta-aspnet/blob/master/docs/aspnetcore-webapi.md</a> but to no avail.</p>
  <p>This is the stack trace:</p>
  <pre><code>Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler[3]
    Exception occurred while processing message.
    System.InvalidOperationException: IDX20803: Unable to obtain configuration from: 'https://company.oktapreview.com/oauth2/aus17ct73zmZrZjbh0h8/.well-known/openid-configuration'.
       at Microsoft.IdentityModel.Protocols.ConfigurationManager`1.GetConfigurationAsync(CancellationToken cancel)
       at Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync()
  
  </code></pre>
  <p>Here is my config in program.cs</p>
  <pre><code>using Lamar;
  using Lamar.Microsoft.DependencyInjection;
  using Microsoft.IdentityModel.Logging;
  using Microsoft.OpenApi.Models;
  using NCL.StockSupplyChain.Common.Configuration;
  using NCL.StockSupplyChain.PurchaseOrder.Web.API;
  using NCL.StockSupplyChain.PurchaseOrder.Web.API.Classes;
  using NCL.StockSupplyChain.ServiceInventory.Token;
  using NCL.StockSupplyChain.ServiceInventory.Workflow;
  using Okta.AspNetCore;
  
  var corsPolicyName = &quot;EnableCors&quot;;
  
  var builder = WebApplication.CreateBuilder(args);
  
  var logger = builder.Logging.Services.BuildServiceProvider().GetRequiredService&lt;ILogger&lt;Program&gt;&gt;();
  
  IdentityModelEventSource.ShowPII = true;
  
  // use Lamar as DI.
  builder.Host.UseLamar()
      .ConfigureContainer&lt;ServiceRegistry&gt;(builder =&gt;
      {
          builder.Scan(x =&gt;
          {
              x.AssembliesFromApplicationBaseDirectory(filter =&gt; filter.FullName is not null &amp;&amp; filter.FullName.StartsWith(&quot;NCL.&quot;));
              x.TheCallingAssembly();
              x.RegisterConcreteTypesAgainstTheFirstInterface();
          });
      });
  
  builder.Services.AddControllers()
      .AddJsonOptions(jsonOptions =&gt; jsonOptions.JsonSerializerOptions.PropertyNamingPolicy = null);
  builder.Services
      .AddRouting(options =&gt; options.LowercaseUrls = true)
      .AddSwaggerGen(c =&gt;
      {
          c.SwaggerDoc(&quot;v1&quot;, new OpenApiInfo { Title = &quot;NCL.StockSupplyChain.PurchaseOrder.Web.API&quot;, Version = &quot;v1&quot; });
      })
      .AddCors(options =&gt;
      {
          options.AddPolicy(name: corsPolicyName,
              corsBuilder =&gt;
              {
                  var allowedOrigins = builder.Configuration.Get&lt;Configuration&gt;().Cors?.AllowedOrigins;
  
                  if (allowedOrigins?.Any() ?? false)
                  {
                      corsBuilder.WithOrigins(allowedOrigins.ToArray())
                          .AllowAnyHeader()
                          .AllowAnyMethod();
                  }
              });
      })
      .AddHttpClient()
      .Configure&lt;Configuration&gt;(builder.Configuration)
      .Configure&lt;ConnectionStringsConfiguration&gt;(builder.Configuration.GetSection(&quot;ConnectionStrings&quot;))
      .Configure&lt;WorkflowConfiguration&gt;(builder.Configuration.GetSection(&quot;WorkflowService&quot;))
      .Configure&lt;TokenConfiguration&gt;(builder.Configuration.GetSection(&quot;TokenService&quot;))
      .AddLogging()
      .AddAuthentication(options =&gt;
      {
          options.DefaultAuthenticateScheme = OktaDefaults.ApiAuthenticationScheme;
          options.DefaultChallengeScheme = OktaDefaults.ApiAuthenticationScheme;
          options.DefaultSignInScheme = OktaDefaults.ApiAuthenticationScheme;
      })
      .AddOktaWebApi(new OktaWebApiOptions()
      {
          OktaDomain = &quot;https://company.oktapreview.com&quot;,
          AuthorizationServerId = &quot;aus17ct73zmZrZjbh0h8&quot;,
          BackchannelHttpClientHandler = new MyLoggingHandler(logger),
      });
  
  var app = builder.Build();
  
  if (app.Environment.IsDevelopment())
  {
      app.UseDeveloperExceptionPage()
          .UseSwagger()
          .UseSwaggerUI(c =&gt; c.SwaggerEndpoint(&quot;/swagger/v1/swagger.json&quot;, &quot;NCL.StockSupplyChain.PurchaseOrder.Web.API&quot;));
  }
  
  app.UseHttpsRedirection()
      .UseRouting()
      .UseAuthorization()
      .UseCors(corsPolicyName)
      .UseEndpoints(endpoints =&gt;
      {
          endpoints.MapControllers();
      });
  
  await app.RunAsync();
  </code></pre>
  <p>Does anyone know what I could be missing? This has left me scratching my head.</p>