Okta RedirectUri failing during callback in .net 8 MVC application

I am working on a .Net 8 core MVC application, where we are implementing Okta authentication. Post successful okta authentication the control comes back to the ‘challenge’ method when I don’t use a redirectUri, as expected.
But when I need Okta to post back to a different controller method post authentication, I am getting the below error.

The DevTools shows that the POST callback is invoked

The ‘state’ and ‘code’ payload are available in the request

Then there is immediately a invocation to GET method on the callback resulting in the failure

So, basically below line runs fine without issues

if (!this.HttpContext.User.Identity.IsAuthenticated)
{
return Challenge(OpenIdConnectAuthenticationDefaults.AuthenticationType);

No Failure

But this line fails…
return Challenge(new AuthenticationProperties { RedirectUri=ConfigUtils.GetConfigValue(“Okta:RedirectUri”)}, OpenIdConnectAuthenticationDefaults.AuthenticationType);

Any insight into this will be very helpful.
Thanks

I am the original author of the post and since I am unable to edit the post after 4 modifications, as requested by Okta services teams, I am adding the repro steps with code snippets

Program.cs (okta configuration)


builder.Services.ConfigureApplicationCookie(options =>
{
options.Cookie.HttpOnly = true;
options.Cookie.SecurePolicy = CookieSecurePolicy.Always;
})
.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie()
.AddOktaMvc(new OktaMvcOptions
{
OktaDomain = builder.Configuration.GetValue(“Okta:OktaDomain”),
AuthorizationServerId = builder.Configuration.GetValue(“Okta:AuthorizationServerId”),
ClientId = builder.Configuration.GetValue(“Okta:ClientId”),
ClientSecret = builder.Configuration.GetValue(“Okta:ClientSecret”),
CallbackPath = “/Authentication/Callback”,
Scope = [“openid”, “profile”, “offline_access”]
});

LoginController.cs (where challenge is invoked for okta authentication)

// GET: Login
public virtual ActionResult Index()
{
if (!this.HttpContext.User.Identity.IsAuthenticated)
{
return Challenge(OktaDefaults.MvcAuthenticationScheme);
//return Challenge(new AuthenticationProperties { RedirectUri=ConfigUtils.GetConfigValue(“Okta:RedirectUri”)}, OktaDefaults.MvcAuthenticationScheme);
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.