2017 © Pedro Peláez
 

library discourse-php

Helper class for building a single sign-on source for Discourse forums

image

cviebrock/discourse-php

Helper class for building a single sign-on source for Discourse forums

  • Friday, July 7, 2017
  • by cviebrock
  • Repository
  • 6 Watchers
  • 46 Stars
  • 48,944 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 20 Forks
  • 0 Open issues
  • 5 Versions
  • 14 % Grown

The README.md

Discourse Single-Sign-On Helper for PHP

This is a small class to help with providing an SSO source for Discourse forums. It provides 3 helper functions for validating incoming requests, extracting nonce, and building the returning query string., (*1)

For more information on the SSO settings in Discourse, visit https://meta.discourse.org/t/official-single-sign-on-for-discourse/13045, (*2)

Original code from Johan Jatko: https://github.com/ArmedGuy/discourse_sso_php, (*3)

Installation

The package is registered at Packagist as cviebrock/discourse-php and can be installed using composer:, (*4)

composer require "cviebrock/discourse-php"

Usage

$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);

Bugs, Suggestions and Contributions

Please use Github for bugs, comments, suggestions., (*5)

  1. Fork the project.
  2. Create your bugfix/feature branch and write your (well-commented) code.
  3. Commit your changes and push to your repository.
  4. Create a new pull request against this project's master branch.

discourse-php was written by Colin Viebrock and released under the MIT License. See the LICENSE file for details., (*6)

Copyright 2015 Colin Viebrock, (*7)

The Versions

07/07 2017

dev-master

9999999-dev https://github.com/cviebrock/discourse-php

Helper class for building a single sign-on source for Discourse forums

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

forum discourse

07/07 2017

0.9.3

0.9.3.0 https://github.com/cviebrock/discourse-php

Helper class for building a single sign-on source for Discourse forums

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

forum discourse

28/08 2016

0.9.2

0.9.2.0 https://github.com/cviebrock/discourse-php

Helper class for building a single sign-on source for Discourse forums

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

forum discourse

20/01 2015

0.9.1

0.9.1.0 https://github.com/cviebrock/discourse-php

Helper class for building a single sign-on source for Discourse forums

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

forum discourse

20/01 2015

0.9.0

0.9.0.0 https://github.com/cviebrock/discourse-php

Helper class for building a single sign-on source for Discourse forums

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

forum discourse