Skip to content

permitio/permit-php

Repository files navigation

Permit PHP SDK

Authorization as a service

Installation & Usage

Requirements

PHP 7.4 and later. Should also work with PHP 8.0.

Composer

To install the bindings via Composer, add the following to composer.json:

{
  "repositories": [
    {
      "type": "vcs",
      "url": "https://github.com/permitio/permit-php.git"
    }
  ],
  "require": {
    "permitio/permit-php": "*@dev"
  }
}

Then run composer install

Manual Installation

Download the files and include autoload.php:

<?php
require_once('/path/to/OpenAPIClient-php/vendor/autoload.php');

Getting Started

Please follow the installation procedure and then run the following:

<?php

require 'vendor/autoload.php';

use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use React\Http\Server;
use Psr\Http\Message\ServerRequestInterface;
use React\EventLoop\Factory;
use React\Socket\SocketServer;


$permitToken = '<Place your Permit Token here>';
$pdpUrl = 'https://cloudpdp.api.permit.io';
$apiUrl = 'https://api.permit.io';
$port = 4000;

$config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setAccessToken($permitToken)->setHost($apiUrl);

// Get the scope of the API key
$apiInstance = new OpenAPI\Client\Api\APIKeysApi(
    new GuzzleHttp\Client(),
    $config
);
try {
    $scope = $apiInstance->getApiKeyScope();
    print_r($scope);
} catch (Exception $e) {
    echo 'Exception when calling APIKeys';
}

$usersInstance = new OpenAPI\Client\Api\UsersApi(
    new GuzzleHttp\Client(),
    $config
);

// Create user with the given data
$user_create = new \OpenAPI\Client\Model\UserCreate([
    'key' => 'raz-cohen',
    'email' => '[email protected]',
    'first_name' => 'Raz',
    'last_name' => 'Cohen',
]);
try {
    $result = $usersInstance->createUser($scope->getProjectId(), $scope->getEnvironmentId(), $user_create);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling UsersApi->createUser: ', $e->getMessage(), PHP_EOL;
}


// Permit check function
$pdpConfig = OpenAPI\Client\Configuration::getDefaultConfiguration()->setAccessToken($permitToken)->setHost($pdpUrl);
$pdpInstance = new OpenAPI\Client\Api\PDP\AuthorizationAPIApi(
    new GuzzleHttp\Client(),
    $pdpConfig
);
// Create a query object - this is the data we want to check
// in this case we're checking if the user 'raz-cohen' is allowed to read a document
$query = new \OpenAPI\Client\Model\PDP\Query([
    'user' => ['key' => 'raz-cohen'],
    'action' => 'read',
    'resource' => [
        'type' => 'document',
        'tenant' => 'default'
    ]
]);
try {
    $is_allowed = $pdpInstance->isAllowedAllowedPost(
        $query,
    );

    // We'll print the result to the console
    if ($is_allowed->getAllow()) {
        echo "Permitted\n";
    } else {
        echo "Not Permitted\n";
    }
} catch (Exception $e) {
    echo 'Exception when calling PDP\AuthorizationAPIApi->isAllowedAllowedPost: ', $e->getMessage(), PHP_EOL;
}

API Endpoints

All URIs are relative to http://localhost

Class Method HTTP request Description
APIKeysApi createApiKey POST /v2/api-key Create Api Key
APIKeysApi deleteApiKey DELETE /v2/api-key/{api_key_id} Delete Api Key
APIKeysApi getApiKey GET /v2/api-key/{api_key_id} Get Api Key
APIKeysApi getApiKeyScope GET /v2/api-key/scope Get Api Key Scope
APIKeysApi getEnvironmentApiKey GET /v2/api-key/{proj_id}/{env_id} Get Environment Api Key
APIKeysApi listApiKeys GET /v2/api-key List Api Keys
AuditElementsDataApi elementsListAuditLogs GET /v2/elements/{proj_id}/{env_id}/config/{elements_config_id}/data/audit_logs List audit logs
AuditLogsApi getDetailedAuditLog GET /v2/pdps/{proj_id}/{env_id}/audit_logs/{log_id} Get detailed audit log
AuditLogsApi listAuditLogs GET /v2/pdps/{proj_id}/{env_id}/audit_logs List Audit Logs
AuthenticationApi devLogin POST /v2/auth/devlogin (DEV MODE) Login
AuthenticationApi elementsLoginAs POST /v2/auth/elements_login_as Elements Login As
AuthenticationApi login POST /v2/auth/login Login
AuthenticationApi loginElements GET /v2/auth/login_elements Login Elements
AuthenticationApi logoutGet GET /v2/auth/logout Logout Get
AuthenticationApi logoutPost POST /v2/auth/logout Logout Post
AuthenticationApi me GET /v2/auth/me Me
AuthenticationApi switchOrganization POST /v2/auth/switch_org/{org_id} Switch Organization
ConditionSetRulesApi assignSetPermissions POST /v2/facts/{proj_id}/{env_id}/set_rules Assign Set Permissions
ConditionSetRulesApi listSetPermissions GET /v2/facts/{proj_id}/{env_id}/set_rules List Set Permissions
ConditionSetRulesApi unassignSetPermissions DELETE /v2/facts/{proj_id}/{env_id}/set_rules Unassign Set Permissions
ConditionSetsApi createConditionSet POST /v2/schema/{proj_id}/{env_id}/condition_sets Create Condition Set
ConditionSetsApi deleteConditionSet DELETE /v2/schema/{proj_id}/{env_id}/condition_sets/{condition_set_id} Delete Condition Set
ConditionSetsApi getConditionSet GET /v2/schema/{proj_id}/{env_id}/condition_sets/{condition_set_id} Get Condition Set
ConditionSetsApi listConditionSets GET /v2/schema/{proj_id}/{env_id}/condition_sets List Condition Sets
ConditionSetsApi updateConditionSet PATCH /v2/schema/{proj_id}/{env_id}/condition_sets/{condition_set_id} Update Condition Set
DecisionLogsApi listPdpDecisionLogs GET /v2/pdps/{proj_id}/{env_id}/decision-logs/{pdp_id} List PDP Decisions
DecisionLogsIngressApi insertOpaDecisionLogs POST /v2/decision-logs/ingress OPA Decision Logs Ingress
DefaultApi dummy GET /v2/stress/dummy Dummy
DefaultApi dummyDb GET /v2/stress/db/dummy Dummy Db
DefaultApi getOrganizationV2StressDbOrganizationGet GET /v2/stress/db/organization Get Organization
DefaultApi getOrganizationWithAuthn GET /v2/stress/db/organization_auth Get Organization With Authn
DefaultApi getOrganizationWithAuthz GET /v2/stress/db/organization_authz Get Organization With Authz
ElementsConfigsApi createElementsConfig POST /v2/elements/{proj_id}/{env_id}/config Create Elements Config
ElementsConfigsApi deleteElementsConfig DELETE /v2/elements/{proj_id}/{env_id}/{elements_config_id} Delete Elements Config
ElementsConfigsApi getElementsConfig GET /v2/elements/{proj_id}/{env_id}/config/{elements_config_id} Get Elements Config
ElementsConfigsApi getElementsConfigRuntime GET /v2/elements/{proj_id}/{env_id}/config/{elements_config_id}/runtime Get Elements Config Runtime
ElementsConfigsApi getElementsTypeConfig GET /v2/elements/{proj_id}/{env_id}/{element_type} Get Elements Type Config
ElementsConfigsApi listElementsConfigs GET /v2/elements/{proj_id}/{env_id}/config List Elements Configs
ElementsConfigsApi updateElementsConfig PATCH /v2/elements/{proj_id}/{env_id}/config/{elements_config_id} Update Elements Config
ElementsConfigsApi updateElementsTypePermissions PATCH /v2/elements/{proj_id}/{env_id}/{element_type} Update Elements Type Permissions
EnvironmentsApi createEnvironment POST /v2/projects/{proj_id}/envs Create Environment
EnvironmentsApi deleteEnvironment DELETE /v2/projects/{proj_id}/envs/{env_id} Delete Environment
EnvironmentsApi getEnvironment GET /v2/projects/{proj_id}/envs/{env_id} Get Environment
EnvironmentsApi listEnvironments GET /v2/projects/{proj_id}/envs List Environments
EnvironmentsApi statsEnvironments GET /v2/projects/{proj_id}/envs/{env_id}/stats Stats Environments
EnvironmentsApi updateEnvironment PATCH /v2/projects/{proj_id}/envs/{env_id} Update Environment
InstructionsApi listLanguageInstructions GET /v2/{proj_id}/{env_id}/get_instructions List Language Instructions
MembersApi deleteOrganizationMember DELETE /v2/members/{member_id} Delete Organization Member
MembersApi getAuthenticatedMember GET /v2/members/me Get the authenticated account member
MembersApi getOrganizationMember GET /v2/members/{member_id} Get Organization Member
MembersApi listOrganizationMembers GET /v2/members List Organization Members
MembersApi updateOrganizationMember PATCH /v2/members/{member_id} Update Organization Member
OPALDataApi getAllData GET /v2/internal/opal_data/{org_id}/{proj_id}/{env_id} Get All Data
OPALDataApi getDataForRole GET /v2/internal/opal_data/{org_id}/{proj_id}/{env_id}/roles/{role_id} Get Data For Role
OPALDataApi getDataForSetRule GET /v2/internal/opal_data/{org_id}/{proj_id}/{env_id}/condition_set_rules/{user_set_id}/{resource_set_id} Get Data For Set Rule
OPALDataApi getDataForUser GET /v2/internal/opal_data/{org_id}/{proj_id}/{env_id}/users/{user_id} Get Data For User
OrganizationsApi cancelInvite DELETE /v2/orgs/{org_id}/invites/{invite_id} Cancel Invite
OrganizationsApi createOrganization POST /v2/orgs Create Organization
OrganizationsApi deleteOrganization DELETE /v2/orgs/{org_id} Delete Organization
OrganizationsApi getActiveOrganization GET /v2/orgs/active/org Get Active Organization
OrganizationsApi getOrganization GET /v2/orgs/{org_id} Get Organization
OrganizationsApi inviteMembersToOrganization POST /v2/orgs/{org_id}/invites Invite Members To Organization
OrganizationsApi listOrganizationInvites GET /v2/orgs/{org_id}/invites List Organization Invites
OrganizationsApi listOrganizations GET /v2/orgs List Organizations
OrganizationsApi updateOrganization PATCH /v2/orgs/{org_id} Update Organization
PolicyApi getOpalDataSources GET /v2/opal/data/config Get Opal Data Sources
PolicyApi getOpalDataSourcesOpalDataConfigGet GET /opal/data/config Get Opal Data Sources
PolicyDecisionPointsApi getAuthenticatingPdpConfigValues POST /v2/pdps/me/config Get connected PDP configuration and push state
PolicyDecisionPointsApi getAuthenticatingPdpConfigValuesLegacy GET /v2/pdps/me/config Get connected PDP configuration
PolicyDecisionPointsApi getPdpConfigValues GET /v2/pdps/{proj_id}/{env_id}/configs/{pdp_id}/values Get PDP configuration
PolicyDecisionPointsApi listPdpConfigs GET /v2/pdps/{proj_id}/{env_id}/configs List PDP configurations
PolicyDecisionPointsApi rotatePdpApiKey POST /v2/pdps/{proj_id}/{env_id}/configs/{pdp_id}/rotate-api-key Rotate PDP API Key
PolicyGitRepositoriesApi activatePolicyRepo PUT /v2/projects/{proj_id}/repos/{repo_id}/activate Activate Policy Repo
PolicyGitRepositoriesApi createPolicyRepo POST /v2/projects/{proj_id}/repos Create Policy Repo
PolicyGitRepositoriesApi deletePolicyRepo DELETE /v2/projects/{proj_id}/repos/{repo_id} Delete Policy Repo
PolicyGitRepositoriesApi disableActivePolicyRepo PUT /v2/projects/{proj_id}/repos/disable Disable Active Policy Repo
PolicyGitRepositoriesApi getActivePolicyRepo GET /v2/projects/{proj_id}/repos/active Get Active Policy Repo
PolicyGitRepositoriesApi getPolicyRepo GET /v2/projects/{proj_id}/repos/{repo_id} Get Policy Repo
PolicyGitRepositoriesApi listPolicyRepos GET /v2/projects/{proj_id}/repos List Policy Repos
ProjectsApi createProject POST /v2/projects Create Project
ProjectsApi deleteProject DELETE /v2/projects/{proj_id} Delete Project
ProjectsApi getProject GET /v2/projects/{proj_id} Get Project
ProjectsApi listProjects GET /v2/projects List Projects
ProjectsApi updateProject PATCH /v2/projects/{proj_id} Update Project
ResourceActionsApi createResourceAction POST /v2/schema/{proj_id}/{env_id}/resources/{resource_id}/actions Create Resource Action
ResourceActionsApi deleteResourceAction DELETE /v2/schema/{proj_id}/{env_id}/resources/{resource_id}/actions/{action_id} Delete Resource Action
ResourceActionsApi getResourceAction GET /v2/schema/{proj_id}/{env_id}/resources/{resource_id}/actions/{action_id} Get Resource Action
ResourceActionsApi listResourceActions GET /v2/schema/{proj_id}/{env_id}/resources/{resource_id}/actions List Resource Actions
ResourceActionsApi updateResourceAction PATCH /v2/schema/{proj_id}/{env_id}/resources/{resource_id}/actions/{action_id} Update Resource Action
ResourceAttributesApi createResourceAttribute POST /v2/schema/{proj_id}/{env_id}/resources/{resource_id}/attributes Create Resource Attribute
ResourceAttributesApi deleteResourceAttribute DELETE /v2/schema/{proj_id}/{env_id}/resources/{resource_id}/attributes/{attribute_id} Delete Resource Attribute
ResourceAttributesApi getResourceAttribute GET /v2/schema/{proj_id}/{env_id}/resources/{resource_id}/attributes/{attribute_id} Get Resource Attribute
ResourceAttributesApi listResourceAttributes GET /v2/schema/{proj_id}/{env_id}/resources/{resource_id}/attributes List Resource Attributes
ResourceAttributesApi updateResourceAttribute PATCH /v2/schema/{proj_id}/{env_id}/resources/{resource_id}/attributes/{attribute_id} Update Resource Attribute
ResourceInstancesApi createResourceInstance POST /v2/facts/{proj_id}/{env_id}/resource_instances Create Resource Instance
ResourceInstancesApi deleteResourceInstance DELETE /v2/facts/{proj_id}/{env_id}/resource_instances/{instance_id} Delete Resource Instance
ResourceInstancesApi getResourceInstance GET /v2/facts/{proj_id}/{env_id}/resource_instances/{instance_id} Get Resource Instance
ResourceInstancesApi listResourceInstances GET /v2/facts/{proj_id}/{env_id}/resource_instances List Resource Instances
ResourceInstancesApi updateResourceInstance PATCH /v2/facts/{proj_id}/{env_id}/resource_instances/{instance_id} Update Resource Instance
ResourceRolesApi addParentResourceRole PUT /v2/schema/{proj_id}/{env_id}/resources/{resource_id}/roles/{role_id}/parents/{parent_role_id} Add Parent Role
ResourceRolesApi assignPermissionsToResourceRole POST /v2/schema/{proj_id}/{env_id}/resources/{resource_id}/roles/{role_id}/permissions Assign Permissions to Role
ResourceRolesApi createResourceRole POST /v2/schema/{proj_id}/{env_id}/resources/{resource_id}/roles Create Resource Role
ResourceRolesApi deleteResourceRole DELETE /v2/schema/{proj_id}/{env_id}/resources/{resource_id}/roles/{role_id} Delete Resource Role
ResourceRolesApi getResourceRole GET /v2/schema/{proj_id}/{env_id}/resources/{resource_id}/roles/{role_id} Get Resource Role
ResourceRolesApi listResourceRoles GET /v2/schema/{proj_id}/{env_id}/resources/{resource_id}/roles List Resource Roles
ResourceRolesApi removeParentResourceRole DELETE /v2/schema/{proj_id}/{env_id}/resources/{resource_id}/roles/{role_id}/parents/{parent_role_id} Remove Parent Role
ResourceRolesApi removePermissionsFromResourceRole DELETE /v2/schema/{proj_id}/{env_id}/resources/{resource_id}/roles/{role_id}/permissions Remove Permissions from Role
ResourceRolesApi updateResourceRole PATCH /v2/schema/{proj_id}/{env_id}/resources/{resource_id}/roles/{role_id} Update Resource Role
ResourcesApi createResource POST /v2/schema/{proj_id}/{env_id}/resources Create Resource
ResourcesApi deleteResource DELETE /v2/schema/{proj_id}/{env_id}/resources/{resource_id} Delete Resource
ResourcesApi getResource GET /v2/schema/{proj_id}/{env_id}/resources/{resource_id} Get Resource
ResourcesApi listResources GET /v2/schema/{proj_id}/{env_id}/resources List Resources
ResourcesApi replaceResource PUT /v2/schema/{proj_id}/{env_id}/resources/{resource_id} Replace Resource
ResourcesApi updateResource PATCH /v2/schema/{proj_id}/{env_id}/resources/{resource_id} Update Resource
RoleAssignmentsApi assignRole POST /v2/facts/{proj_id}/{env_id}/role_assignments Assign Role
RoleAssignmentsApi listRoleAssignments GET /v2/facts/{proj_id}/{env_id}/role_assignments List Role Assignments
RoleAssignmentsApi unassignRole DELETE /v2/facts/{proj_id}/{env_id}/role_assignments Unassign Role
RolesApi addParentRole PUT /v2/schema/{proj_id}/{env_id}/roles/{role_id}/parents/{parent_role_id} Add Parent Role
RolesApi assignPermissionsToRole POST /v2/schema/{proj_id}/{env_id}/roles/{role_id}/permissions Assign Permissions To Role
RolesApi createRole POST /v2/schema/{proj_id}/{env_id}/roles Create Role
RolesApi deleteRole DELETE /v2/schema/{proj_id}/{env_id}/roles/{role_id} Delete Role
RolesApi getRole GET /v2/schema/{proj_id}/{env_id}/roles/{role_id} Get Role
RolesApi listRoles GET /v2/schema/{proj_id}/{env_id}/roles List Roles
RolesApi removeParentRole DELETE /v2/schema/{proj_id}/{env_id}/roles/{role_id}/parents/{parent_role_id} Remove Parent Role
RolesApi removePermissionsFromRole DELETE /v2/schema/{proj_id}/{env_id}/roles/{role_id}/permissions Remove Permissions From Role
RolesApi updateRole PATCH /v2/schema/{proj_id}/{env_id}/roles/{role_id} Update Role
TenantsApi createTenant POST /v2/facts/{proj_id}/{env_id}/tenants Create Tenant
TenantsApi deleteTenant DELETE /v2/facts/{proj_id}/{env_id}/tenants/{tenant_id} Delete Tenant
TenantsApi deleteTenantUser DELETE /v2/facts/{proj_id}/{env_id}/tenants/{tenant_id}/users/{user_id} Delete Tenant User
TenantsApi getTenant GET /v2/facts/{proj_id}/{env_id}/tenants/{tenant_id} Get Tenant
TenantsApi listTenantUsers GET /v2/facts/{proj_id}/{env_id}/tenants/{tenant_id}/users List Tenant Users
TenantsApi listTenants GET /v2/facts/{proj_id}/{env_id}/tenants List Tenants
TenantsApi updateTenant PATCH /v2/facts/{proj_id}/{env_id}/tenants/{tenant_id} Update Tenant
UserAttributesApi createUserAttribute POST /v2/schema/{proj_id}/{env_id}/users/attributes Create User Attribute
UserAttributesApi deleteUserAttribute DELETE /v2/schema/{proj_id}/{env_id}/users/attributes/{attribute_id} Delete User Attribute
UserAttributesApi getUserAttribute GET /v2/schema/{proj_id}/{env_id}/users/attributes/{attribute_id} Get User Attribute
UserAttributesApi listUserAttributes GET /v2/schema/{proj_id}/{env_id}/users/attributes List User Attributes
UserAttributesApi updateUserAttribute PATCH /v2/schema/{proj_id}/{env_id}/users/attributes/{attribute_id} Update User Attribute
UsersApi assignRoleToUser POST /v2/facts/{proj_id}/{env_id}/users/{user_id}/roles Assign Role To User
UsersApi createUser POST /v2/facts/{proj_id}/{env_id}/users Create User
UsersApi deleteUser DELETE /v2/facts/{proj_id}/{env_id}/users/{user_id} Delete User
UsersApi getUser GET /v2/facts/{proj_id}/{env_id}/users/{user_id} Get User
UsersApi listUsers GET /v2/facts/{proj_id}/{env_id}/users List Users
UsersApi replaceUser PUT /v2/facts/{proj_id}/{env_id}/users/{user_id} Replace User
UsersApi unassignRoleFromUser DELETE /v2/facts/{proj_id}/{env_id}/users/{user_id}/roles Unassign Role From User
UsersApi updateUser PATCH /v2/facts/{proj_id}/{env_id}/users/{user_id} Update User
UsersElementsDataApi elementsAssignRoleToUser POST /v2/elements/{proj_id}/{env_id}/config/{elements_config_id}/data/users/{user_id}/roles Assign role to user
UsersElementsDataApi elementsCreateUser POST /v2/elements/{proj_id}/{env_id}/config/{elements_config_id}/data/users Create user
UsersElementsDataApi elementsDeleteUser DELETE /v2/elements/{proj_id}/{env_id}/config/{elements_config_id}/data/users/{user_id} Delete user
UsersElementsDataApi elementsListRoles GET /v2/elements/{proj_id}/{env_id}/config/{elements_config_id}/data/roles List roles
UsersElementsDataApi elementsListUsers GET /v2/elements/{proj_id}/{env_id}/config/{elements_config_id}/data/users List users
UsersElementsDataApi elementsUnassignRoleFromUser DELETE /v2/elements/{proj_id}/{env_id}/config/{elements_config_id}/data/users/{user_id}/roles Unassign role from user
UsersElementsDataApi setConfigActive POST /v2/elements/{proj_id}/{env_id}/config/{elements_config_id}/data/active Set Config Active

Models

Authorization

HTTPBearer

  • Type: Bearer authentication (JWT)

Tests

To run the tests, use:

composer install
vendor/bin/phpunit

Author

About this package

This PHP package is automatically generated by the OpenAPI Generator project:

  • API version: 2.0.0
  • Build package: org.openapitools.codegen.languages.PhpClientCodegen

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages