Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • dev-thandabantu 3 posts 72 karma points
    1 week ago
    dev-thandabantu
    0

    HttpContext in Umbraco 10

    Hi,

    I am trying to do something similar to this solution, but in Umbraco 10 and I haven't been successful. Please help. In other words, what's the equivalent of this in Umbraco 10?

    var t = new HttpContextWrapper(HttpContext.Current).GetUmbracoAuthTicket()

  • Huw Reddick 660 posts 2153 karma points
    1 week ago
    Huw Reddick
    0

    Hi,

    Not sure if this is what you need, but I am using this code in a middleware component I use to protect some Media folders

    private bool IsBackofficeUser(HttpContext context, IOptionsSnapshot<CookieAuthenticationOptions> cookieOptionsSnapshot)
    {
        CookieAuthenticationOptions cookieOptions = cookieOptionsSnapshot.Get(Umbraco.Cms.Core.Constants.Security.BackOfficeAuthenticationType);
        string backOfficeCookie = context.Request.Cookies[cookieOptions.Cookie.Name!];
        AuthenticationTicket unprotected = cookieOptions.TicketDataFormat.Unprotect(backOfficeCookie!);
        ClaimsIdentity backOfficeIdentity = new ClaimsIdentity();
        if (unprotected != null)
        {
            backOfficeIdentity = unprotected!.Principal.GetUmbracoIdentity();
        }
        return backOfficeIdentity.IsAuthenticated;
    }
    

    The class that calls this has IOptionsSnapshot<CookieAuthenticationOptions> injected in it's constructor

Please Sign in or register to post replies

Write your reply to:

Draft