hansadema / jsconnect
Composer version of Vanilla Forums jsConnect
Installs: 16 083
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 0
Forks: 2
Open Issues: 2
Requires
- php: >=5.4.0
This package is auto-updated.
Last update: 2024-12-17 01:02:29 UTC
README
Rebuild of the official jsConnect PHP library for Vanilla Forums. PSR compliant and easily installable through Composer.
Installation
Add the composer dependency:
composer require hansadema/jsconnect
Usage
The example below shows a standard use case for a logged in user.
<?php require_once '../vendor/autoload.php'; // Setup a Jsconnect instance $jsConnect = new \HansAdema\JsConnect\JsConnect('YOUR CLIENT ID', 'YOUR CLIENT SECRET'); // Build a user object $user = new \HansAdema\JsConnect\User([ 'id' => 1234, 'name' => 'Example User', 'email' => 'user@example.com', 'photoUrl' => 'http://example.com/user.jpg', 'roles' => ['member', 'administrator'], ]); // Try to build the response $response = $jsConnect->buildResponse($user, $_GET); // Return the JSONP result echo $_GET['callback'].'('.json_encode($response).')';
If the user is not logged in, the user object can be left empty. If there is an error, you can return an error with the response data:
$response = [ 'error' => 'invalid_client', 'message' => 'Your Custom Error Message', ];