harbargerdev
harbargerdev

Reputation: 31

Okta IDX20803: Unable to obtain configuration from: 'System.String' with .NET 5

I have been doing some digging around and spinning my tires looking through documentation for the better part of the afternoon and I can't seem to find where my problem lies. I have a .NET 5 Web API that we are trying to configure to use OKTA for OAuth Authentication/Authorization. I have followed the tutorial steps in this document (https://developer.okta.com/docs/guides/protect-your-api/aspnetcore3/configure-packages/) and I am getting the above Error (IDX20803: Unable to obtain configuratoin from 'System.String').

In my Startup.cs, configure services has the following:

...
services.AddAuthentication(options =>
{
    options.DefaultAuthenticateScheme = OktaDefaults.ApiAuthenticationScheme;
    options.DefaultChallengeScheme = OktaDefaults.ApiAuthenticationScheme;
    options.DefaultSignInScheme = OktaDefaults.ApiAuthenticationScheme;
})
.AddOktaWebApi(new OktaWebApiOptions()
{
    OktaDomain = $"{Environment.GetEnvironmentVariable("OKTA_URL")}"
});

services.AddAuthorization();
...

And my Statup.cs Configure section contains the following:

...
app.UseAuthentication();

app.UseAuthorization();
...

I am assuming it is something in my setup, but again, I have done this per the documentation, including configuring CORS as well, but I no matter what I do I do the IDX20803 Exception.

Upvotes: 2

Views: 1034

Answers (1)

harbargerdev
harbargerdev

Reputation: 31

After discussing this with my security engineer that actually setup the Okta OAuth in Okta itself, it clicked what the problem was. We were missing two pieces in the Okta Setup, see below:

services.AddAuthentication(options =>
{
    options.DefaultAuthenticateScheme = OktaDefaults.ApiAuthenticationScheme;
    options.DefaultChallengeScheme = OktaDefaults.ApiAuthenticationScheme;
    options.DefaultSignInScheme = OktaDefaults.ApiAuthenticationScheme;
}
.AddOktaWebApi(new OktaWebApiOptions()
{
    OktaDomain = $"{Environment.GetEnvironmentVariable("OKTA_URL")}",
    AuthorizationServerId = Environment.GetEnvironmentVariable("OKTA_AUTH_SERVER_ID"),
    Audience = Environment.GetEnvironmentVariable("OKTA_AUDIENCE")
});

The key was I need the OktaDomain, AuthorizationServiceId, and Audience, which weren't referenced in the references I was using. Hopefully this will solve other's issues in the future.

Upvotes: 0

Related Questions