vinkas/discourse-php

This package is abandoned and no longer maintained. The author suggests using the vinkas/discourse package instead.

PHP library to authenticate your forum using Discourse Connect

v2.1.0 2024-11-23 17:34 UTC

This package is auto-updated.

Last update: 2024-11-23 17:37:40 UTC


README

Tests Packagist Version

PHP library to authenticate your forum using Discourse Connect

Installation

The package vinkas/discourse can be installed using composer via packagist.

composer require vinkas/discourse

Documentation

Creating a Discourse client

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

Discourse Connect

$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);

Visit https://meta.discourse.org/t/setup-discourseconnect-official-single-sign-on-for-discourse-sso/13045 for more details about Discourse Connect.