PHPackages                             sammaye/yii2-discourse-sso - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. sammaye/yii2-discourse-sso

ActiveProject[Framework](/categories/framework)

sammaye/yii2-discourse-sso
==========================

A set of tools for Discourse unicorns.

1.0(8y ago)121.2k2BSD-3-ClausePHPPHP &gt;=5.4.0

Since Dec 13Pushed 8y ago5 watchersCompare

[ Source](https://github.com/Sammaye/yii2-discourse-sso)[ Packagist](https://packagist.org/packages/sammaye/yii2-discourse-sso)[ Docs](http://www.sammaye.wordpress.com/)[ RSS](/packages/sammaye-yii2-discourse-sso/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

yii2-discourse-sso
==================

[](#yii2-discourse-sso)

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](https://meta.discourse.org/t/official-single-sign-on-for-discourse/13045) 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.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 87.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3078d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7357836d822160350576f98b85244f4d5f960be303a2fcaa15a330187966cbd4?d=identicon)[Sammaye](/maintainers/Sammaye)

---

Top Contributors

[![Sammaye](https://avatars.githubusercontent.com/u/323996?v=4)](https://github.com/Sammaye "Sammaye (7 commits)")[![stereochrome](https://avatars.githubusercontent.com/u/812066?v=4)](https://github.com/stereochrome "stereochrome (1 commits)")

---

Tags

frameworkSSOyii2discourse

### Embed Badge

![Health badge](/badges/sammaye-yii2-discourse-sso/health.svg)

```
[![Health](https://phpackages.com/badges/sammaye-yii2-discourse-sso/health.svg)](https://phpackages.com/packages/sammaye-yii2-discourse-sso)
```

###  Alternatives

[yidas/yii2-bower-asset

Bower Assets for Yii 2 app provided via Composer repository

331.2M30](/packages/yidas-yii2-bower-asset)[tecnocen/yii2-formgenerator

Yii 2 Library to configure form generator

145.7k](/packages/tecnocen-yii2-formgenerator)[sammaye/yii2-elephantio

A plugin for using Elephant IO with Yii2

118.4k](/packages/sammaye-yii2-elephantio)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
