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
erlend_sh
(Erlend Sogge Heggen)
2016 年 10 月 7 日午前 11:47
3
I haven’t looked closely at this but it sounds like there might be some overlap with @michaeld ’s PHP API client for Discourse:
PHP API client for Discourse
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
「いいね!」 1
michaeld
(Michael - Communiteq)
2016 年 10 月 7 日午後 4:05
5
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
pnoeric
(Eric)
2020 年 3 月 23 日午後 3:48
7
このトピックを見つけたばかりの方へ(現在は2020年3月です…自宅でのCOVID-19隔離からこんにちは!)–
上記で言及されている@michaeldさんのライブラリは、APIとの通信のみに特化したもののようです。これは実際にはSSOとは関係ありません。
@vinothkannansさんがGitHubで共有したライブラリを試してみましたが 、彼自身が上記で述べている通り、十分なテストがされておらず、実際には非常にバグが多く、本番環境での使用にはまだ適していません。
こちらを見つけ、私にはうまく機能しています:
A PHP class for helping with Discourse's SSO login
「いいね!」 9