Copied to clipboard

Flag this post as spam?

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


  • Shelly 9 posts 79 karma points
    Nov 12, 2023 @ 13:57
    Shelly
    0

    Umbraco10 - Atuhentication cookie

    Hello,

    I'm using umbraco version 10.7.0

    I want to use Auth cookie in order to go to a protected node, and I want this authentication cookie to have an EXPIRATION TIME OF 20 MINUTES.

    I try to use:

    If the umbraco member exists: Microsoft.AspNetCore.Identity.SignInResult result3 = Task.Run(async () => await _signInManager.PasswordSignInAsync(Username, Password, false, false)).Result;

    If the Umbraco member does not exist:

    IdentityResult result2 = Task.Run(async () => await RegisterMemberAsync(RM)).Result;

    private async Task

    if (string.IsNullOrEmpty(model.Name) && string.IsNullOrEmpty(model.Email) == false)
    {
        model.Name = model.Email;
    }
    
    model.Username = model.UsernameIsEmail || model.Username == null ? model.Email : model.Username;
    
    var identityUser =
        MemberIdentityUser.CreateNew(model.Username, model.Email, model.MemberTypeAlias, true, model.Name);
    
    IdentityResult identityResult = await _memberManager.CreateAsync(
        identityUser,
        model.Password);
    
    if (identityResult.Succeeded)
    {
    
        IMember? member = _memberService.GetByKey(identityUser.Key);
        if (member == null)
        {
    
            throw new InvalidOperationException($"Could not find a member with key: {member?.Key}.");
        }
    
        foreach (MemberPropertyModel property in model.MemberProperties.Where(p => p.Value != null).Where(property => member.Properties.Contains(property.Alias)))
        {
            member.Properties[property.Alias]?.SetValue(property.Value);
        }
    
        //Before we save the member we make sure to assign the group, for this the "Group" must exist in the backoffice.
        string memberGroup = "Regular";
        AssignMemberGroup(model.Email, memberGroup);
    
        _memberService.Save(member);
    
        if (logMemberIn)
        {
            await _signInManager.SignInAsync(identityUser, false);
        }
    }
    
    return identityResult;
    

    }

    For this one - the authentication cookie itself works perfect but I don't know how to set the expiration time to be 20 minutes. Can anyone help me to do it?

  • Liam Dilley 172 posts 402 karma points
    Sep 11, 2024 @ 02:59
    Liam Dilley
    0

    This is a while ago now but you do have in appsettings...

    Umbraco - CMS - Security - MemberDefaultLockoutTimeInMinutes

Please Sign in or register to post replies

Write your reply to:

Draft