This library provides a comprehensive PHP interface for integrating with the Community of Trust (COT) platform, facilitating seamless interactions with its services.
- PHP >= 7.4
- Composer for managing dependencies
To install the library, run the following command in your project directory:
composer require trstd/cot-integration-libraryHere is a basic example of how to use the library:
On the backend side:
<?php
require_once 'vendor/autoload.php';
use TRSTD\COT\Client;
// Initialize the client
$client = new Client(
<CLIENT_ID>, // Client ID - e.g. 'cot-switch-X1234567890123456789012345678901'
<CLIENT_SECRET>, // Client Secret - e.g. '1234567890123456789012345678901234567890123456789012345678901234'
<AUTH_STORAGE_INSTANCE>, // It can be any storage option implementing AuthStorageInterface - e.g. new DatabaseAuthStorage()
<ENV> // Environment (optional) - dev, qa, or prod, defaults to prod
);
// Invoke handleCallback function to handle code coming from the authentication server
$client->handleCallback();
// Get consumer data for the current user
$consumerData = $client->getConsumerData();
// Access consumer information
if ($consumerData) {
$firstName = $consumerData->getFirstName();
$membershipStatus = $consumerData->getMembershipStatus();
$membershipSince = $consumerData->getMembershipSince();
}On the frontend side, place the following code in your HTML file where you want the widget to appear:
<trstd-login tsId="X1234567890123456789012345678901"></trstd-login>
<script type="module" src="https://cdn.trstd-login.trstd.com/trstd-login/script.js"></script>For more detailed examples, please refer to the examples/ directory.
- PHP >= 7.4
- Composer
- Docker (optional, for containerized development)
-
Install dependencies:
composer install
-
Generate certificates (for HTTPS testing):
make certs
-
Start development environment:
make dev
-
Create configuration file:
cp test-environment/config.example.php test-environment/config.php
-
Update configuration with your credentials:
<?php return [ 'tlciid' => 'YOUR_ACTUAL_TLCIID', 'client_id' => 'YOUR_ACTUAL_CLIENT_ID', 'client_secret' => 'YOUR_ACTUAL_CLIENT_SECRET', 'environment' => 'qa' ]; ?>
The project includes a comprehensive Makefile with the following commands:
make dev- Start Docker with live file watchingmake docker-stop- Stop Docker environment
make certs- Generate self-signed localhost TLS certs for HTTPS (8443)
The project includes a test environment for development and testing:
-
Start the test environment:
make dev
-
Access the test page:
- HTTPS (recommended): https://localhost:8443/oauth-integration-test.php
- HTTP (dev only): http://localhost:8081/oauth-integration-test.php
-
Run automated tests:
make test
For debugging with Xdebug:
-
Start Xdebug in your IDE first (Cursor, VS Code, PhpStorm)
-
Run development environment:
make dev
-
Set breakpoints in your PHP code
-
Visit test page: https://localhost:8443/oauth-integration-test.php
-
Code will pause at breakpoints for inspection
Important: Always start Xdebug in IDE before running make dev. The environment will attach to your IDE's debugger on host.docker.internal:9003.
Contributions are welcome! Please refer to the CONTRIBUTING.md file for guidelines.
This library is licensed under the MIT License - see the LICENSE file for details.
- firebase/php-jwt for JWT handling
- phpseclib/phpseclib for security features
- monolog/monolog for logging
- symfony/http-client for HTTP client features
This project adheres to Semantic Versioning. For the versions available, see the tags on this repository.
This library is available on Packagist.