Пример #1
0
 public IEnumerable <Permission> GetPermissions()
 {
     if (!(PermissionValues is null))
     {
         foreach (var p in PermissionValues.Where(o => o.Value))
         {
             if (Permission.TryCreatePermission(p.Permission, null, out var pp))
             {
                 yield return(pp);
             }
         }
     }
     if (this.StoreMode == ApiKeyStoreMode.AllStores)
     {
         if (StoreManagementPermission.Value)
         {
             yield return(Permission.Create(Policies.CanModifyStoreSettings));
         }
     }
     else if (this.StoreMode == ApiKeyStoreMode.Specific && SpecificStores is List <string> )
     {
         foreach (var p in SpecificStores)
         {
             if (Permission.TryCreatePermission(Policies.CanModifyStoreSettings, p, out var pp))
             {
                 yield return(pp);
             }
         }
     }
 }
Пример #2
0
        internal void CheckPermissions(PermissionValues permissionToCheck)
        {
            var  request        = new RestRequest("tokeninfo");
            var  response       = ExecuteTaskAsync <TokenInfo>(request);
            bool hasPermissions = response.Result.Data != null && response.Result.Data.permissions.Contains(permissionToCheck.ToString());

            if (!hasPermissions)
            {
                throw new InvalidKeyException(permissionToCheck);
            }
        }