### Install and Configure License Connector Source: https://context7.com/laravel-ready/license-connector/llms.txt Instructions for installing the License Connector package via Composer and publishing its configuration file. The configuration allows setting the license server URL. ```bash composer require laravel-ready/license-connector php artisan vendor:publish --tag=license-connector-configs ``` -------------------------------- ### Use LicenseConnector Facade and Service for License Operations (PHP) Source: https://context7.com/laravel-ready/license-connector/llms.txt Demonstrates how to use the LicenseConnector facade and directly instantiate the ConnectorService for license validation. The facade offers a static interface, while direct instantiation allows for explicit license key management. This example shows checking license validity and returning JSON responses. ```php validateLicense()) { return response()->json([ 'valid' => true, 'license' => $connector->license ]); } return response()->json(['valid' => false], 403); } } ``` -------------------------------- ### Configure License Server URL Source: https://context7.com/laravel-ready/license-connector/llms.txt Example of how to configure the license server URL in the published configuration file (`config/license-connector.php`). This URL is used for all license validation requests. ```php env('LICENSE_SERVER_URL', 'https://your-license-server.com'), ]; ``` -------------------------------- ### Install Laravel License Connector via Composer Source: https://github.com/laravel-ready/license-connector/blob/main/README.md Installs the license connector package into your Laravel project using Composer. This is the primary method for adding the package's functionality. ```bash composer require laravel-ready/license-connector ``` -------------------------------- ### Integrate License Validation in Laravel Application Boot Process (PHP) Source: https://context7.com/laravel-ready/license-connector/llms.txt Provides a complete example of integrating license validation into the Laravel application's boot process using a Service Provider. It includes checks for development environments, configuration of the license key, and handling of authentication exceptions. Valid licenses result in license information being stored in the application instance. ```php validateApplicationLicense(); } private function validateApplicationLicense(): void { // Skip in local/testing environments if (app()->environment(['local', 'testing'])) { return; } $licenseKey = config('app.license_key'); if (empty($licenseKey)) { abort(503, 'Application license key not configured'); } try { $connector = new ConnectorService($licenseKey); $isValid = $connector->validateLicense([ 'domain' => config('app.url'), 'version' => config('app.version', '1.0.0') ]); if (!$isValid) { abort(503, 'Application license is invalid or expired'); } // Store license info for later use app()->instance('license.info', $connector->license); } catch (AuthException $e) { report($e); abort(503, 'Unable to verify application license'); } } } ``` -------------------------------- ### License Server API Endpoints for Authentication and Validation (HTTP) Source: https://context7.com/laravel-ready/license-connector/llms.txt Details the API endpoints used by the ConnectorService for license server authentication and validation. It specifies the HTTP methods, URLs, request payloads, headers, and example responses for both the login and license validation endpoints. These are called internally by the service. ```http group(function () { Route::get('/protected-resource', function () { return response()->json(['message' => 'Access granted']); }); Route::post('/licensed-feature', [LicensedFeatureController::class, 'store']); }); // Example controller using middleware class LicensedFeatureController extends Controller { public function __construct() { $this->middleware('license-connector'); } public function store(Request $request) { // Domain is automatically merged into request by middleware $domain = $request->input('domain'); return response()->json([ 'domain' => $domain, 'status' => 'feature activated' ]); } } // Client request must include host headers // curl -X GET https://your-app.com/protected-resource \ // -H "_Host: https://client-domain.com" \ // -H "_Host_Name: Client Application" ``` -------------------------------- ### Exception Handling Source: https://context7.com/laravel-ready/license-connector/llms.txt The package provides custom exceptions for handling authentication and license-related errors. These exceptions can be caught to manage specific error scenarios gracefully. ```APIDOC ## Exception Handling ### Description The package provides custom exceptions for handling authentication and license-related errors. These exceptions can be caught to manage specific error scenarios gracefully. ### Method (Internal service method, not a direct API endpoint) ### Endpoint N/A ### Parameters N/A ### Request Example ```php validateLicense(); return [ 'success' => true, 'valid' => $isValid, 'license' => $isValid ? $connector->license : null ]; } catch (AuthException $e) { // Authentication with license server failed // Invalid license key, server unreachable, or token issues return [ 'success' => false, 'error' => 'authentication_failed', 'message' => $e->getMessage() ]; } catch (LicenseConnectorException $e) { // General connector errors return [ 'success' => false, 'error' => 'connector_error', 'message' => $e->getMessage() ]; } } } // Usage $service = new LicenseService(); $result = $service->validateUserLicense('invalid-key-12345'); // Returns: ['success' => false, 'error' => 'authentication_failed', 'message' => '...'] ``` ### Response (Example responses from the `validateUserLicense` method) #### Success Response ```json { "success": true, "valid": true, "license": { "license_key": "46fad906-bc51-435f-9929-db46cb4baf13", "expires_at": "2025-12-31T23:59:59Z" } } ``` #### Error Response (Authentication Failed) ```json { "success": false, "error": "authentication_failed", "message": "Invalid license key provided." } ``` #### Error Response (Connector Error) ```json { "success": false, "error": "connector_error", "message": "Failed to connect to the license server." } ``` ``` -------------------------------- ### Validate License with ConnectorService Source: https://github.com/laravel-ready/license-connector/blob/main/README.md Demonstrates how to validate a license using the ConnectorService. It takes a license key and optionally custom data, returning a boolean indicating validity and license details if valid. ```php use LaravelReady\LicenseConnector\Services\ConnectorService; ... $licenseKey = '46fad906-bc51-435f-9929-db46cb4baf13'; $connectorService = new ConnectorService($licenseKey); $isLicenseValid = $connectorService->validateLicense(); if ($isLicenseValid) { // License is valid echo 'License is valid'; print_r($connectorService->license); } else { // License is invalid echo 'License is not valid'; } ``` ```php $customData = ['email' => 'testa@example.com']; $isLicenseValid = $connectorService->validateLicense($customData); ``` -------------------------------- ### Publish License Connector Configuration Source: https://github.com/laravel-ready/license-connector/blob/main/README.md Publishes the configuration files for the license connector package to your Laravel project. This allows you to customize settings according to your needs. ```bash php artisan vendor:publish --tag=license-connector-configs ``` -------------------------------- ### LicenseConnector Facade Source: https://context7.com/laravel-ready/license-connector/llms.txt The LicenseConnector facade provides a convenient static interface for accessing the connector service. Direct service instantiation is recommended for explicit license key handling. ```APIDOC ## LicenseConnector Facade ### Description The `LicenseConnector` facade provides a convenient static interface for accessing the connector service throughout your application. Direct service instantiation is recommended for explicit license key handling. ### Method (Facade usage, not a direct API endpoint) ### Endpoint N/A ### Parameters N/A ### Request Example ```php validateLicense()) { return response()->json([ 'valid' => true, 'license' => $connector->license ]); } return response()->json(['valid' => false], 403); } } ``` ### Response (Depends on the underlying service method) #### Success Response (200) (Example based on controller usage) ```json { "valid": true, "license": { "license_key": "46fad906-bc51-435f-9929-db46cb4baf13", "expires_at": "2025-12-31T23:59:59Z" } } ``` #### Response Example (Example based on controller usage) ```json { "valid": false } ``` ``` -------------------------------- ### POST /api/license-server/auth/login Source: https://context7.com/laravel-ready/license-connector/llms.txt Authenticates with the license server to obtain an access token. This endpoint is called automatically by the `ConnectorService`. ```APIDOC ## POST /api/license-server/auth/login ### Description Authenticates with the license server to obtain an access token. This endpoint is called automatically by the `ConnectorService`. ### Method POST ### Endpoint `{license_server_url}/api/license-server/auth/login` ### Parameters #### Request Body - **license_key** (string) - Required - The license key for authentication. #### Headers - **x-host** (string) - Required - The host URL of the application making the request (e.g., `https://your-app.com`). - **x-host-name** (string) - Required - The name of the application making the request. ### Request Example ```json { "license_key": "46fad906-bc51-435f-9929-db46cb4baf13" } ``` ### Response #### Success Response (200) - **status** (boolean) - Indicates if the authentication was successful. - **access_token** (string) - The access token for subsequent requests. #### Response Example ```json { "status": true, "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..." } ``` ``` -------------------------------- ### POST /api/license-server/license Source: https://context7.com/laravel-ready/license-connector/llms.txt Validates the license key by checking its status and expiration. This endpoint is called by the `validateLicense()` method. ```APIDOC ## POST /api/license-server/license ### Description Validates the license key by checking its status and expiration. This endpoint is called by the `validateLicense()` method. ### Method POST ### Endpoint `{license_server_url}/api/license-server/license` ### Parameters #### Query Parameters - **domain** (string) - Optional - The domain to validate the license against. - **version** (string) - Optional - The application version to validate the license against. #### Headers - **Authorization** (string) - Required - Bearer token obtained from the authentication endpoint (e.g., `Bearer {access_token}`). - **x-host** (string) - Required - The host URL of the application making the request (e.g., `https://your-app.com`). - **x-host-name** (string) - Required - The name of the application making the request. ### Request Example (No explicit request body is shown for this endpoint in the provided documentation, but query parameters can be appended to the URL) ### Response #### Success Response (200) - **status** (string) - The status of the license (e.g., "active"). - **license_key** (string) - The validated license key. - **expires_at** (string) - The expiration date and time of the license in ISO 8601 format. - ... (other license-related details) #### Response Example ```json { "status": "active", "license_key": "46fad906-bc51-435f-9929-db46cb4baf13", "expires_at": "2025-12-31T23:59:59Z" } ``` ``` -------------------------------- ### Handle License Connector Exceptions (PHP) Source: https://context7.com/laravel-ready/license-connector/llms.txt Illustrates how to handle custom exceptions like AuthException and LicenseConnectorException when validating user licenses. This provides robust error management for authentication failures, server unreachability, or general connector issues. The function returns a structured array indicating success or failure with error details. ```php validateLicense(); return [ 'success' => true, 'valid' => $isValid, 'license' => $isValid ? $connector->license : null ]; } catch (AuthException $e) { // Authentication with license server failed // Invalid license key, server unreachable, or token issues return [ 'success' => false, 'error' => 'authentication_failed', 'message' => $e->getMessage() ]; } catch (LicenseConnectorException $e) { // General connector errors return [ 'success' => false, 'error' => 'connector_error', 'message' => $e->getMessage() ]; } } } // Usage $service = new LicenseService(); $result = $service->validateUserLicense('invalid-key-12345'); // Returns: ['success' => false, 'error' => 'authentication_failed', 'message' => '...'] ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.