I just started using Okta in a new ASP.NET Core application yesterday. It was working fine, but I must have changed something, because now I’m getting a “Correlation failed” error when trying to test it.
I put an [Authorize] attribute on an action. I go to that action, I get redirected to Okta, I login, and here’s the error message I get after getting redirected back:
Your code looks fine so it should be configuration.
Regardless of the ASP.NET version you are using your login redirect uri should be http://localhost:xxxx/authorization-code/callback in your App configuration.
Can you tell me what are the settings of the Authorization server you have created?
You can see this in the Settings tab after clicking the Authorization Server.
It seems you have removed the default AS. Is there any reason why did you do it?
The Okta ASP.NET middleware uses the default AS by default, but you can still configure it to use your custom AS.
Add the next line in your OktaMvcOptions
AuthorizationServerId = "auslewqw....";
Here you can see how we create the issuer url:
Also, you might need to create a new access policy for your AS, if you don’t have any specific requirements create a new one with a policy rule and keep the default settings.
You can do this by clicking the Access Policies tab.
Unfortunately, it’s not possible to restore the default. But you should be fine by creating a new access policy with a default policy rule.
Also, the default Audience is api://default you can set this as well.
I’m making some progress, I guess. After creating a AS with a rule and specifying that in the OktaMvcOptions, I’m finally past that 404 error. But now I’m back to the some “Correlation failed” exception again.
That’s a good call. I can’t share the project, but I decided to create a minimum reproduction project to share with you instead. When I did this, it worked fine! So I did a quick compare and figured out the problem:
ASPNET Core MVC template by default includes this in Startup.cs -> ConfigureServices:
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
And this in Startup.cs -> Configure:
app.UseCookiePolicy();
I had removed the part from ConfigureServices but not from Configure. I tested it, and I need to have both removed or both included, otherwise I will get the correlation error. Thank you for helping me solve this!
That is super interesting. aspnetcore saves a local cookie right before it redirects to Okta (this is built into aspnetcore, not an Okta thing) to save state and prevent CSRF on the redirect. Without the right cookie policy, it was probably being blocked somewhere.
Glad you got it working!
FYI, there isn’t anything special about the default AS - other than being a shortcut to having to create all the access policies from scratch. If you create one yourself, you can just define those policies and it works the same way.
I’m having another issue where I’m getting a “correlation failed” error, but this time it’s after the user clicks the “verify email” link from the email they receive. Everything else still works fine. I didn’t notice this until recently, because I had already verified my email address before I started coding (but now other people are trying it out).
Another piece of information: I also get this exact same error when using the okta-aspnetcore-mvc-example. (I did make one minor change to specify the AuthorizationServerId, see above, but otherwise I’m using the stock example).
Confirming as above. used the okta-aspnetcore-mvc-example and my custom .net core app, and getting the below error:
An unhandled exception occurred while processing the request.
Exception: Correlation failed.
Unknown location
Exception: An error was encountered while handling the remote login.
Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler<TOptions>.HandleRequestAsync()
This issue might cause because of your login URL might be change from Account/Login to any other url. As Identity has default url is Account/login. For more detail you can find in below document http://docs.identityserver.io/en/latest/topics/signin.html
I have resolved this issue by adding below line
services.AddIdentityServer(options =>
{
options.UserInteraction.LoginUrl = new PathString("/AccountUI/Login");
options.UserInteraction.LogoutUrl = new PathString("/AccountUI/Logout");
})