Copied to clipboard

Flag this post as spam?

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


  • GianniDPC 7 posts 73 karma points
    Aug 10, 2022 @ 11:51
    GianniDPC
    0

    CookieAuthentication not working in website

    CookieAuthentication seems not to be working as expected in my Umbraco 10 project. I'm using Umbraco 10.1.0.

    It seems to be creating the Authentication Cookie but User.Identity.Name is always NULL.

    I added this line to ConfigureServices:

    services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
                .AddCookie(options =>
                {
                    options.LoginPath = "/Login";
                    options.Cookie.Name = "RubioAuthCookie";
                    options.ExpireTimeSpan = TimeSpan.FromMinutes(20);
                    options.SlidingExpiration = true;
                });
    

    and I added these lines to the Configure method:

    app.UseUmbraco()
                    .WithMiddleware(u =>
                    {
                        u.UseBackOffice();
                        u.UseWebsite();
    
                        u.AppBuilder.UseAuthentication();
                        u.AppBuilder.UseAuthorization();
    

    This is the code from within my Login action:

    [Route("/Account/Login")]
    public async Task<IActionResult> LoginAsync()
    {
        var claims = new List<Claim>
        {
            new Claim(ClaimTypes.Name, "Gianni"),
        };
    
        var identity = new ClaimsIdentity(claims,
            CookieAuthenticationDefaults.AuthenticationScheme);
    
        await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(identity), new AuthenticationProperties { IsPersistent = true});
    
        return Redirect("/");
    }
    

    What am I doing wrong or what could be causing this issue?

  • Sof 1 post 71 karma points
    1 week ago
    Sof
    0

    Hello, I just came up with the same issue. Did you maybe find a solution to this problem?

Please Sign in or register to post replies

Write your reply to:

Draft