Okta Middleware being hit first for some reason

So I’m trying to implement Okta in my MVC application, and it already has a cookie authentication set up and the pipeline is set in the following manner:

app.SetDefaultSignInAsAuthenticationType(DefaultAuthenticationTypes.ApplicationCookie);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
//this is used for an already existing authentication mechanism and has some settings like LoginPath.
           
app.UseOktaMvc(new OktaMvcOptions());
//with credentials passed ofcourse;

When i run the application I believe a 401 error is hit first itself, which used to be intercepted by the cookie middleware and would redirect to the login page. But now that i added Okta middleware, Okta keeps intercepting it and redirects to Okta login page and not my local login page in spite of defining the pipeline correctly(?). Any help?

By any chance you checked okta-aspnet/docs/aspnet4x-mvc.md at master · okta/okta-aspnet · GitHub '?

I was able to find out the usage of LoginMode.SelfHosted and it worked!

Now i face another issue where the discovery endpoint is not being hit by my middleware as the request fails. But when i manually use a HttpClient object and request the same endpoint from my application, it works. I’m working in a corporate environment so I’m not sure if there’s a proxy causing the issue.

In any case, if I’m able to use HttpClient and send the request from my app, the Okta middleware which internally also uses HttpClient should be able to send the request as well right?

yes, it should work if you are able to use HttpClient. Please, let us know if it works

It was an internal exception due to some assembly file missing and now that’s resolved.

1 Like

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