Discourse SSO and API Helper for PHP

Installation

The package is registered at Packagist as vinkas/discourse-php and can be installed using composer:

composer require vinkas/discourse-php

Usage

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

API

$api = $discourse->api('API_KEY', 'API_USERNAME');
$api->topics()->create('TITLE', 'CONTENT', 'CATEGORY_SLUG')

SSO

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

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

if (!($sso->isValid())) {
    header("HTTP/1.1 403 Forbidden");
    echo("Bad SSO 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/official-single-sign-on-for-discourse/13045
);

$url = $sso->getResponseUrl($userParams)
header('Location: ' . $url);
exit(0);
6개의 좋아요

Since I committed in other task I didn’t tested the code well and unable to give detailed documentation with usage examples.

I will release next version soon with more options, documentation and examples.

1개의 좋아요

I haven’t looked closely at this but it sounds like there might be some overlap with @michaeld’s PHP API client for Discourse:

https://github.com/communiteq/discourse-api-php

I already aware of this existing package. But I didn’t used it. I used famous GuzzleHttp (they used php native curl) and composer. Also in mine it have SSO option too.

After all I created this package because of I am also creating laravel package (which depends it) for easy implementation with laravel features like eloquent model. Yes few laravel packages also already exist for discourse. But I have something different in my mind for development :slight_smile:

1개의 좋아요

Too bad you decided to create another, instead of just contributing to what already existed, and making it better.

Sorry @michaeld. Coding structure which I wanted and created is totally different from your existing package. That’s why I created it as new one.

In other words I created this package for my own purpose. Then I decided to open source it.

1개의 좋아요

이 주제를 이제야 발견하신 분들을 위해 (지금 2020년 3월입니다… 코로나19 자가격리 중인 집에서 인사드립니다!) –

위에서 언급된 @michaeld의 라이브러리는 API와 통신하는 데만 사용되는 것으로 보입니다. 이는 SSO와 실제로는 아무런 관련이 없습니다.

@vinothkannans가 Github에 공유한 라이브러리를 사용해 보고 있는데, 그가 위에서 말했듯이 많은 테스트를 하지 않았고, 실제로도 버그가 많고 아직 본격적인 사용에는 적합하지 않은 것 같습니다.

다음 라이브러리를 찾았고, 제 환경에서는 잘 작동하고 있습니다:

9개의 좋아요