trstd / cot-integration-library
A PHP integration library for connecting to Community of Trust platform.
Installs: 112
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 1
pkg:composer/trstd/cot-integration-library
Requires
- php: >=7.4
- firebase/php-jwt: ^6
- monolog/monolog: ^2
- phpseclib/phpseclib: ^3
- psr/cache: ^1.0 || ^2.0
- symfony/http-client: ^5
Requires (Dev)
README
This library provides a comprehensive PHP interface for integrating with the Community of Trust (COT) platform, facilitating seamless interactions with its services.
Requirements
- PHP >= 7.4
- Composer for managing dependencies
Installation
To install the library, run the following command in your project directory:
composer require trstd/cot-integration-library
Usage
Here 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.
Development
Prerequisites
- PHP >= 7.4
- Composer
- Docker (optional, for containerized development)
Setup
-
Install dependencies:
composer install
-
Generate certificates (for HTTPS testing):
make certs
-
Start development environment:
make dev
Configuration
-
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' ]; ?>
Development Commands
The project includes a comprehensive Makefile with the following commands:
🐳 Docker Environment
make dev- Start Docker with live file watchingmake docker-stop- Stop Docker environment
🔐 Certificates
make certs- Generate self-signed localhost TLS certs for HTTPS (8443)
Testing
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
Debugging
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.
Contributing
Contributions are welcome! Please refer to the CONTRIBUTING.md file for guidelines.
License
This library is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- firebase/php-jwt for JWT handling
- phpseclib/phpseclib for security features
- monolog/monolog for logging
- symfony/http-client for HTTP client features
Versioning
This project adheres to Semantic Versioning. For the versions available, see the tags on this repository.
PHP Package Repository
This library is available on Packagist.