GetCurrentMemberAsync() in IMemberManager doesn't ...
# help-with-umbraco
j
hey out there, this one is slightly mystifying us... we've a site where members (not backoffice users) are authenticating against an identity server. everything is working and we're able to set the claims on the member when they login. however when we call the
GetCurrentMemberAsync()
method in
IMemberManager
interface the claims are always empty despite them being present on the
HttpContext.User
this seems kinda weird seeing
GetCurrentMemberAsync()
calls
GetUserAsync(user)
which passes the user in?
Copy code
Umbraco.Cms.Web.Common.Security.MemberManager

/// <inheritdoc />
public virtual async Task<MemberIdentityUser?> GetCurrentMemberAsync()
{
    if (_currentMember == null)
    {
        if (!IsLoggedIn())
        {
            return null;
        }

        _currentMember = await GetUserAsync(_httpContextAccessor.HttpContext?.User!);
    }

    return _currentMember;
}
is there something we're missing?! https://cdn.discordapp.com/attachments/1295939400336805908/1295939400919810089/image.png?ex=6710791e&is=670f279e&hm=9fcfd1de66ae5e85ba42859f45f0aa493c1ef297b8ff91924637659557f25ecb&
we can map the claims up if we have our own member manager that inherits from `MemberManager`:
Copy code
public class SiteMemberManager : MemberManager
{
    public SiteMemberManager(IIpResolver ipResolver, IMemberUserStore store, IOptions<IdentityOptions> optionsAccessor, IPasswordHasher<MemberIdentityUser> passwordHasher, IEnumerable<IUserValidator<MemberIdentityUser>> userValidators, IEnumerable<IPasswordValidator<MemberIdentityUser>> passwordValidators, IdentityErrorDescriber errors, IServiceProvider services, ILogger<UserManager<MemberIdentityUser>> logger, IOptionsSnapshot<MemberPasswordConfigurationSettings> passwordConfiguration, IPublicAccessService publicAccessService, IHttpContextAccessor httpContextAccessor) : base(ipResolver, store, optionsAccessor, passwordHasher, userValidators, passwordValidators, errors, services, logger, passwordConfiguration, publicAccessService, httpContextAccessor)
    {
    }

    public override async Task<MemberIdentityUser?> GetCurrentMemberAsync()
    {
        var baseMember = await base.GetCurrentMemberAsync();

        return baseMember;
    }

    public override async Task<MemberIdentityUser?> GetUserAsync(ClaimsPrincipal principal)
    {
        var baseMember = await base.GetUserAsync(principal);

        if (baseMember == null || !principal.Claims.Any())
        {
            return baseMember;
        }

        foreach (var claim in principal.Claims)
        {
            baseMember.Claims.Add(new IdentityUserClaim<string>
            {
                ClaimType = claim.Type,
                ClaimValue = claim.Value,
                UserId = baseMember.Id
            });
        }

        return baseMember;
    }
}
the
GetUserAsync(ClaimsPrincipal principal)
method maps the claims in the principal onto the member returned by the base class. but this feels like a completely unnecessary bit of code?!
4 Views