sammaye/yii2-discourse-sso
Composer 安装命令:
composer create-project sammaye/yii2-discourse-sso
包简介
A set of tools for Discourse unicorns.
关键字:
README 文档
README
Discourse SSO for Yii2
Currently this extension only really deals with logging in.
Installing and configuring is quite easy.
Make sure to follow this guide on Discourse and while setting up SSO, after getting the secret needed, configure your application like so:
'discourseSso' => [
'class' => 'sammaye\discourse\Sso',
'secret' => "Some super secret, super awesome dupa secret key"
],
That is this extension installed. Now you just need to learn how to use it.
Your extension is accessible via Yii::$app->discourseSso. This is the location used throughout this readme.
The first step is to setup a action in your SiteController.php to actually do the logic of signing in someone:
public function actionDiscourseSso()
{
$request = Yii::$app->getRequest();
$sso = Yii::$app->discourseSso;
$payload = $request->get('sso');
$sig = $request->get('sig');
if(!($sso->validate($payload, $sig))){
// invaild, deny
throw new ForbiddenHttpException('Bad SSO request');
}
$nonce = $sso->getNonce($payload);
if(Yii::$app->getUser()->isGuest){
// We add session variable to track it after we log the user in so we can redirect them back
// This method works well with custom login methods like social networks
Yii::$app->getSession()->set('sso', ['sso' => $payload, 'sig' => $sig]);
return $this->redirect(['site/login']);
}else{
$user = Yii::$app->getuser()->getIdentity();
}
Yii::$app->getSession()->remove('sso');
// We send over the data
$userparams = [
"nonce" => $nonce,
"external_id" => (String)$user->_id,
"email" => $user->email,
// Optional - feel free to delete these two
"username" => $user->username,
"name" => $user->username,
//'avatar_url' => Url::to(['image/profile-image', 'id' => (String)$user->_id], 'http')
];
$q = $sso->buildLoginString($userparams);
/// We redirect back
header('Location: ' . Yii::getAlias('@discourse') . '/session/sso_login?' . $q);
}
and even though this goes 90% of the way it does not complete it. If you notice:
Yii::$app->getSession()->set('sso', ['sso' => $payload, 'sig' => $sig]);
We load the sig and payload into session so we can tell if we came from single sign-on so we can redirect back. This means that in
our login functions (whether it be login() or some social login) we need to change it to (as an example for login):
public function actionLogin()
{
if (!\Yii::$app->user->isGuest) {
return $this->goHome();
}
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
if($sso = Yii::$app->getSession()->get('sso')){
return $this->redirect([
'discourse-sso',
'sso' => $sso['sso'],
'sig' => $sso['sig']
]);
}
if($model->getUser()->profile_filled){
return $this->goBack();
}else{
return $this->redirect(['user/about-me']);
}
} else {
return $this->render('login', [
'model' => $model,
]);
}
}
Notice the if($sso = Yii::$app->getSession()->get('sso')){, that is where he magic happens, it detects our single sign-on and redirects back to our single sign-on function.
To customise this, just add:
if($sso = Yii::$app->getSession()->get('sso')){
return $this->redirect([
'discourse-sso',
'sso' => $sso['sso'],
'sig' => $sso['sig']
]);
}
to the end of every authentication function you have.
sammaye/yii2-discourse-sso 适用场景与选型建议
sammaye/yii2-discourse-sso 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.42k 次下载、GitHub Stars 达 12, 最近一次更新时间为 2015 年 03 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「SSO」 「yii2」 「discourse」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sammaye/yii2-discourse-sso 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sammaye/yii2-discourse-sso 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sammaye/yii2-discourse-sso 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
A custom URL rule class for Yii 2 which allows to create translated URL rules
SCEditor, a lightweight WYSIWYG BBCode & HTML editor extension for Yii 2.0 Framework
Simple Single Sign-On
Azure Active Directory OAuth 2.0 Client Provider for The PHP League OAuth2-Client
AXIUM Identity Symfony Bundle - Client d'authentification centralisée OAuth2/Keycloak
统计信息
- 总下载量: 1.42k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 12
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2015-03-24