Skip to main content

PHP

Please note that the PHP SDK is autogenerated and developer experience isn't great.

To install the PHP SDK using Composer, run:

composer require ory/hydra-client

Configuration

Basic configuration

Below is a basic configuration that demonstrates how to set the admin and public host. Please note that you need to set the host everytime you want to switch between the admin and public host.

<?php

require_once __DIR__ . "/vendor/autoload.php";

use HydraSDK\Configuration;
use HydraSDK\Api\AdminApi;
use HydraSDK\Api\PublicApi;

$config = new Configuration();
// Configure Admin API
$config->getDefaultConfiguration()->setHost("http://localhost:4445");
$adminApi = new AdminApi();

// Configure Public API
$config->getDefaultConfiguration()->setHost("http://localhost:4444");
$publicApi = new PublicApi();

API Usage

<?php
require_once(__DIR__ . '/vendor/autoload.php');

use HydraSDK\ApiException;
use HydraSDK\Configuration;
use HydraSDK\Api\AdminApi;
use HydraSDK\Api\PublicApi;

try {
$config = new Configuration();
// Configure Admin API
$config->getDefaultConfiguration()->setHost("http://localhost:4445");
$adminApi = new AdminApi();

// List OAuth2 Clients (Admin API)
$clients = $adminApi->listOAuth2Clients();
print_r($clients);

// Configure Public API
$config->getDefaultConfiguration()->setHost("http://localhost:4444");
$publicApi = new PublicApi();

// Discover OpenID Connect Configuration (Public API)
$connect = $publicApi->discoverOpenIDConfiguration();
print_r($connect);
} catch (ApiException $e) {
echo 'Exception occurred: ', $e->getMessage(), PHP_EOL;
}
?>

API docs

API docs are available here. Please note that those docs are generated and may introduce bugs if code examples are used 1:1.