Hi Huzaim
If the application creates a cookie like ".AspNetCore.Identity.Application", then the user is logged in. But maybe not in the way the authorization middleware expects it.
Does it work if you remove "options.DefaultAuthenticateScheme = OpenIdConnectDefaults.AuthenticationScheme;"?
Try changing the .AddAuthentication section to this:
services.AddAuthentication(options =>
{
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
And the beginning of the .AddOpenIdConnect section to this:
.AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, options =>
Another thing. In your OnSignedIn handler you don't await the synchronization of claims. This could potentially be an issue.
I recently did a blog post on implementing ID4 with Optimizely, some of the content in their may be of use to you? https://world.optimizely.com/blogs/allthingsopti/dates/2023/2/a-day-in-the-life-of-an-optimizely-developer---implementing-identity-server-4-and-asp-net-identity/
I was reading through the following blog https://swapcode.wordpress.com/2018/09/24/using-openid-connect-with-episerver/, and it suggested to remove the code related to identity since we are using `ISynchronizingUserService`.
Removed this line,
.AddCmsAspNetIdentity<ApplicationUser>();
and the code worked fine with the OIDC.
Recently I migrated our solution from CMS11 to CMS12.
For the login, we have used our own IdentityServer IDP, which provides all the claims required for the logged in user.
Following is the code i have added to the startup,
I have mapped the custom claims separately, and also used a role claim action to map the role claims that is received as an array from IdentityServer. (It happens when there are more than one claim type returned)
The issue is, even when I call the ISynchronizingUserService, all the required claims are available after the transformation.
However, AddCookie does not seems to create te correct identity cookie and the session.
It does create some cookie, but it does not allow me to login.
In the `StartPageController` , `Login` action, i have called the `Challenge` method.
And the usual happens, shows the IDP login page, once verified, returns back to the OIDC handler, maps the claims and the rest.
What am I missing, why the user does not login ?
Do I have to manually call the HttpContext,SigninAsync ?