コード例 #1
0
        public async Task <IReadOnlyCollection <Permission> > GetPermissionsAsync()
        {
            if (userPermissions == null)
            {
                if (IsAuthenticated)
                {
                    IUser user = await GetUserAsync();

                    userPermissions = await userPermissionResolver.GetUserPermissionsAsync(user);
                }
                else
                {
                    userPermissions = new List <Permission>();
                }
            }

            return(userPermissions);
        }
コード例 #2
0
        public async Task <IUser> GetUserAsync()
        {
            if (user == null)
            {
                if (UserId != null)
                {
                    var httpContext     = httpContextAccessor.HttpContext;
                    var claimsPrincipal = httpContext.User;
                    user = await userManager.GetUserAsync(claimsPrincipal);

                    if (user == null)
                    {
                        throw new InvalidOperationException($"GetUserAsync failed because the authenticated user with ID '{UserId}' could not be found");
                    }
                }
            }

            return(user);
        }