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

1.6.2 2025-12-12 18:17 UTC

README

License CircleCI

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

  1. Install dependencies:

    composer install
  2. Generate certificates (for HTTPS testing):

    make certs
  3. Start development environment:

    make dev

Configuration

  1. Create configuration file:

    cp test-environment/config.example.php test-environment/config.php
  2. 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 watching
  • make 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:

  1. Start the test environment:

    make dev
  2. Access the test page:

  3. Run automated tests:

    make test

Debugging

For debugging with Xdebug:

  1. Start Xdebug in your IDE first (Cursor, VS Code, PhpStorm)

  2. Run development environment:

    make dev
  3. Set breakpoints in your PHP code

  4. Visit test page: https://localhost:8443/oauth-integration-test.php

  5. 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

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.