User PasswordSignInAsync does not persist in Umbraco 14?
In Umbraco 14, when calling _backOfficeSignInManager.PasswordSignInAsync() to sign a backoffice User in:
The return is successful (result.Succeeded == true)
The correct User with a valid Identity and IsAuthenticated = true
A cookie is created (UMB_UCONTEXT=...)
This seems like everything is correct, but it only lasts for the single request. Every subsequent request will have no User or Identity despite having the cookie. What am I missing??
For some reason the UseAuthentication() middleware does not function correctly.
It is added to the pipeline correctly in the Umbraco.Web.Common.UmbracoApplicationBuilder.cs file, the method is RegisterDefaultRequiredMiddleware(). Which is invoked when you call app.UseUmbraco() in your Program.cs file.
For whatever reason however it doesn't work. My guess is that it has something to do with the amount of custom-rolled auth that Umbraco has for Users.
In any case, the application is in the same state as if UseAuthentication() was never added. As per this post, the fix is to add the following Attribute to get the Auth to force re-run
This has to be done on a per-endpoint basis, instead of using just [Authorize]
For example:
public class MustBeAuthedController : UmbracoController
{
[HttpGet]
//[Authorize(Policy = AuthorizationPolicies.BackOfficeAccess)] <-- Will not work
//[Authorize] <-- Will not work
[Authorize(AuthenticationSchemes = Constants.Security.BackOfficeAuthenticationType)]
public IActionResult Index()
{
return View("SomeViewThatRequiresAuth");
}
}
As an aside, figuring out that Constants.Security.BackOfficeAuthenticationType is actually an AuthenticationScheme was very much not obvious
User PasswordSignInAsync does not persist in Umbraco 14?
In Umbraco 14, when calling
_backOfficeSignInManager.PasswordSignInAsync()
to sign a backofficeUser
in:This seems like everything is correct, but it only lasts for the single request. Every subsequent request will have no User or Identity despite having the cookie. What am I missing??
Any help would be very much appreciated!
Figured it out.
For some reason the
UseAuthentication()
middleware does not function correctly.It is added to the pipeline correctly in the
Umbraco.Web.Common.UmbracoApplicationBuilder.cs
file, the method isRegisterDefaultRequiredMiddleware()
. Which is invoked when you callapp.UseUmbraco()
in yourProgram.cs
file.For whatever reason however it doesn't work. My guess is that it has something to do with the amount of custom-rolled auth that Umbraco has for Users.
In any case, the application is in the same state as if
UseAuthentication()
was never added. As per this post, the fix is to add the following Attribute to get the Auth to force re-runThis has to be done on a per-endpoint basis, instead of using just
[Authorize]
For example:
As an aside, figuring out that
Constants.Security.BackOfficeAuthenticationType
is actually anAuthenticationScheme
was very much not obviousis working on a reply...