Skip to content

Pass HttpContextAccessor httpContextAccessor to manager #54

@EvilLord666

Description

@EvilLord666

All manager classes should receive IHttpContextAccessor that could be used as follows:

public static class UserService
    {
        public static Guid GetCurrentUserId(IHttpContextAccessor accessor)
        {
            Claim claim = accessor.HttpContext.User.Claims.FirstOrDefault(c => c.Type == "id");
            if (claim == null)
            {
                string msg = "Authorization server does not contains \"id\" property in UserInfo, ensure that you properly configured your UserProperty Mapper";
                throw new InvalidOperationException(msg);
            }

            return Guid.Parse(claim.Value);
        }
    }

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions