PHP code example of vinkas / discourse-php

1. Go to this page and download the library: Download vinkas/discourse-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vinkas / discourse-php example snippets


$discourse = new Vinkas\Discourse\Client('discourse.example.com', true);  // set true if ssl enabled

$payload = $_GET['sso'];
$signature = $_GET['sig'];

$connect = $discourse->connect('SECRET', $payload, $signature);

if (!($connect->isValid())) {
    header("HTTP/1.1 403 Forbidden");
    echo("Bad Discourse Connect request");
    die();
}

$userParams = array(
    'external_id' => 'USER_ID',
    'email'     => 'EMAIL_ADDRESS',
    'username' => 'USERNAME',  // optional
    'name'     => 'FULL_NAME'  // optional
    // for more available fields https://meta.discourse.org/t/13045
);

$url = $connect->getResponseUrl($userParams)
header('Location: ' . $url);
exit(0);