cviebrock/discourse-php

Discourse 论坛单点登录的辅助类

0.9.3 2017-07-07 16:02 UTC

This package is auto-updated.

Last update: 2024-09-05 18:31:08 UTC


README

这是一个小的类,用于帮助提供 Discourse 论坛的单点登录源。它提供了三个辅助函数,用于验证传入请求、提取 nonce 和构建返回的查询字符串。

有关 Discourse 中单点登录设置的更多信息,请访问 https://meta.discourse.org/t/official-single-sign-on-for-discourse/13045

原始代码来自 Johan Jatko: https://github.com/ArmedGuy/discourse_sso_php

安装

该软件包已在 Packagist 上注册为 cviebrock/discourse-php,并可以使用 composer 安装。

composer require "cviebrock/discourse-php"

使用方法

$sso = new Cviebrock\DiscoursePHP\SSOHelper();

// this should be the same in your code and in your Discourse settings:
$secret = 'super_secret_sso_key';
$sso->setSecret( $secret );

// load the payload passed in by Discourse
$payload = $_GET['sso'];
$signature = $_GET['sig'];

// validate the payload
if (!($sso->validatePayload($payload,$signature))) {
    // invaild, deny
    header("HTTP/1.1 403 Forbidden");
    echo("Bad SSO request");
    die();
}

$nonce = $sso->getNonce($payload);

// Insert your user authentication code here ...

// Required and must be unique to your application
$userId = '...';

// Required and must be consistent with your application
$userEmail = '...';

// Optional - if you don't set these, Discourse will generate suggestions
// based on the email address

$extraParameters = array(
    'username' => $userUsername,
    'name'     => $userFullName
);

// build query string and redirect back to the Discourse site
$query = $sso->getSignInString($nonce, $userId, $userEmail, $extraParameters);
header('Location: http://discourse.example.com/session/sso_login?' . $query);
exit(0);

错误、建议和贡献

请使用 Github 进行错误报告、评论和建议。

  1. 分支项目。
  2. 创建您的错误修复/功能分支,并编写您的(有良好注释的)代码。
  3. 提交您的更改并推送到您的仓库。
  4. 针对此项目的 master 分支创建一个新的 pull request。

版权和许可

discourse-php 由 Colin Viebrock 编写,并按照 MIT 许可证发布。有关详细信息,请参阅 LICENSE 文件。

版权所有 2015 Colin Viebrock