Skip to content

Commit ccfcac1

Browse files
author
Warren Buckley
committed
Merge branch 'chunk-backend-user-cookie' of https://github.com/philipdanielhayton/Our-Umbraco-TagHelpers into philipdanielhayton-chunk-backend-user-cookie
# Conflicts: # Our.Umbraco.TagHelpers/Services/BackofficeUserAccessor.cs Co-authored-by: philipdanielhayton
2 parents 10fa2ef + b5aae72 commit ccfcac1

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

Our.Umbraco.TagHelpers/Services/BackofficeUserAccessor.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using Microsoft.AspNetCore.Authentication;
2-
using Microsoft.AspNetCore.Authentication.Cookies;
1+
using Microsoft.AspNetCore.Authentication.Cookies;
32
using Microsoft.AspNetCore.Http;
43
using Microsoft.Extensions.Options;
54
using System.Security.Claims;
@@ -26,6 +25,11 @@ public BackofficeUserAccessor(
2625
_httpContextAccessor = httpContextAccessor;
2726
}
2827

28+
29+
/// <summary>
30+
/// Updated to use ChunkingCookieManager as per Sean Maloney's answer on our.umbraco.com
31+
/// https://our.umbraco.com/forum/umbraco-9/106857-how-do-i-determine-if-a-backoffice-user-is-logged-in-from-a-razor-view#comment-341847
32+
/// </summary>
2933
public ClaimsIdentity BackofficeUser
3034
{
3135
get
@@ -35,17 +39,18 @@ public ClaimsIdentity BackofficeUser
3539
if (httpContext == null)
3640
return new ClaimsIdentity();
3741

38-
CookieAuthenticationOptions cookieOptions = _cookieOptionsSnapshot.Get(global::Umbraco.Cms.Core.Constants.Security.BackOfficeAuthenticationType);
39-
string? backOfficeCookie = httpContext.Request.Cookies[cookieOptions.Cookie.Name!];
42+
var cookieOptions = _cookieOptionsSnapshot.Get(global::Umbraco.Cms.Core.Constants.Security.BackOfficeAuthenticationType);
43+
var cookieManager = new ChunkingCookieManager();
44+
var backOfficeCookie = cookieManager.GetRequestCookie(httpContext, cookieOptions.Cookie.Name!);
4045

4146
if (string.IsNullOrEmpty(backOfficeCookie))
4247
return new ClaimsIdentity();
4348

44-
AuthenticationTicket? unprotected = cookieOptions.TicketDataFormat.Unprotect(backOfficeCookie!);
45-
ClaimsIdentity? backOfficeIdentity = unprotected?.Principal.GetUmbracoIdentity();
49+
var unprotected = cookieOptions.TicketDataFormat.Unprotect(backOfficeCookie!);
50+
var backOfficeIdentity = unprotected?.Principal.GetUmbracoIdentity();
4651

4752
return backOfficeIdentity ?? new ClaimsIdentity();
4853
}
4954
}
5055
}
51-
}
56+
}

0 commit comments

Comments
 (0)