private static async Task <bool> SessionHasAllPermissionsAsync(IRequest req, IAuthSession session, IAuthRepositoryAsync authRepo, ICollection <string> requiredPermissions)
        {
            if (await session.HasRoleAsync(RoleNames.Admin, authRepo).ConfigAwait())
            {
                return(true);
            }

            if (await requiredPermissions.AllAsync(x => session.HasPermissionAsync(x, authRepo)).ConfigAwait())
            {
                return(true);
            }

            await session.UpdateFromUserAuthRepoAsync(req, authRepo).ConfigAwait();

            if (await requiredPermissions.AllAsync(x => session.HasPermissionAsync(x, authRepo)).ConfigAwait())
            {
                await req.SaveSessionAsync(session).ConfigAwait();

                return(true);
            }

            return(false);
        }
 public virtual async Task <bool> HasAnyPermissionsAsync(IAuthSession session, IAuthRepositoryAsync authRepo)
 {
     return(session != null && await this.RequiredPermissions
            .AnyAsync(requiredPermission => session.HasPermissionAsync(requiredPermission, authRepo)).ConfigAwait());
 }