Due to the business requirements, the project needs to integrate Okta OIDC, but the system has already integrated JWT. Therefore, I have implemented multi-channel authentication with the following code:
services.ConfigureApplicationCookie(options =>
{
options.Cookie.HttpOnly = true;
options.Cookie.SecurePolicy = Microsoft.AspNetCore.Http.CookieSecurePolicy.Always;
})
.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
//options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie()
.AddOktaMvc(new OktaMvcOptions
{
// Replace these values with your Okta configuration
OktaDomain = Appsettings.app("Okta:OktaDomain"),
AuthorizationServerId = "",
ClientId = Appsettings.app("Okta:ClientId"),
ClientSecret = Appsettings.app("Okta:ClientSecret"),
CallbackPath = Appsettings.app("Okta:redirect_uri"),
PostLogoutRedirectUri = Appsettings.app("Okta:signout_redirect_uri")
//Scope = new List<string> { "openid", "profile", "email" },
});
services.AddControllersWithViews();
The system can successfully redirect to the Okta system for authentication and callback to my home page. However, there is always an error when logging out, as shown below:
{
"errorCode": "invalid_client",
"errorSummary": "A client_id must be provided in the request.",
"errorLink": "invalid_client",
"errorId": "oaeYNYRvMnfQxOH4B0KM0A-Og",
"errorCauses": []
}
I tried to add client_id, but I still got the same error. Here is my logout code.
[NoSign]
[Route("/Okta_Signout")]
[Authorize(AuthenticationSchemes = OpenIdConnectDefaults.AuthenticationScheme )]
[HttpGet]
public async Task<IActionResult> SignOut()
{
//await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
string redirectUri = Appsettings.app("Okta:signout_redirect_uri");
var properties = new AuthenticationProperties { RedirectUri = redirectUri };
//properties.Items.Add("client_id", "0oa8j1t2i7iMbRyVW5d7");
//properties.Items.Add("post_logout_redirect_uri", redirectUri);
return SignOut(properties,
CookieAuthenticationDefaults.AuthenticationScheme,
OpenIdConnectDefaults.AuthenticationScheme);
}
I searched online and found that the reason for this issue may be due to the confusion in the .NET Core authentication pipeline. Does anyone have a solution to this? I hope you can help me. Thank you.