Download the PHP package sammaye/yii2-discourse-sso without Composer

On this page you can find all versions of the php package sammaye/yii2-discourse-sso. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package 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 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.


All versions of yii2-discourse-sso with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package sammaye/yii2-discourse-sso contains the following files

Loading the files please wait ....