Skip to content

Grendel7/jsconnect-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vanilla Forums jsConnect for Composer

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' => '[email protected]',
    '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',
];

About

Vanilla Forums jsConnect for PHP, rebuilt for Composer

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages