{"id":34638279,"url":"https://github.com/spinen/laravel-discourse-sso","last_synced_at":"2025-12-24T17:12:27.923Z","repository":{"id":22543572,"uuid":"96646752","full_name":"spinen/laravel-discourse-sso","owner":"spinen","description":"Integrate Discourse SSO into Laravel","archived":false,"fork":false,"pushed_at":"2024-04-14T21:40:28.000Z","size":113,"stargazers_count":49,"open_issues_count":2,"forks_count":14,"subscribers_count":9,"default_branch":"develop","last_synced_at":"2025-09-17T02:53:47.979Z","etag":null,"topics":["discourse","discourse-php","discourse-sso","laravel","laravel-5-package","laravel-discourse-sso","single-sign-on","spinen"],"latest_commit_sha":null,"homepage":"https://spinen.com","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spinen.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2017-07-08T22:07:59.000Z","updated_at":"2025-09-15T15:23:39.000Z","dependencies_parsed_at":"2024-04-14T22:24:23.823Z","dependency_job_id":"f05b158c-d2ca-4625-b141-3fbcf8073624","html_url":"https://github.com/spinen/laravel-discourse-sso","commit_stats":{"total_commits":139,"total_committers":8,"mean_commits":17.375,"dds":"0.40287769784172667","last_synced_commit":"a48aaded67cac01c905b19f5e0226eed3b801ed3"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"purl":"pkg:github/spinen/laravel-discourse-sso","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spinen%2Flaravel-discourse-sso","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spinen%2Flaravel-discourse-sso/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spinen%2Flaravel-discourse-sso/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spinen%2Flaravel-discourse-sso/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spinen","download_url":"https://codeload.github.com/spinen/laravel-discourse-sso/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spinen%2Flaravel-discourse-sso/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28005414,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-24T02:00:07.193Z","response_time":83,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["discourse","discourse-php","discourse-sso","laravel","laravel-5-package","laravel-discourse-sso","single-sign-on","spinen"],"created_at":"2025-12-24T17:10:54.910Z","updated_at":"2025-12-24T17:12:27.907Z","avatar_url":"https://github.com/spinen.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SPINEN's Discourse SSO for Laravel\n\n[![Latest Stable Version](https://poser.pugx.org/spinen/laravel-discourse-sso/v/stable)](https://packagist.org/packages/spinen/laravel-discourse-sso)\n[![Latest Unstable Version](https://poser.pugx.org/spinen/laravel-discourse-sso/v/unstable)](https://packagist.org/packages/spinen/laravel-discourse-sso)\n[![Total Downloads](https://poser.pugx.org/spinen/laravel-discourse-sso/downloads)](https://packagist.org/packages/spinen/laravel-discourse-sso)\n[![License](https://poser.pugx.org/spinen/laravel-discourse-sso/license)](https://packagist.org/packages/spinen/laravel-discourse-sso)\n\n[Discourse](https://www.discourse.org) is a great online forum software that supports Single Sign On ([SSO](https://meta.discourse.org/t/official-single-sign-on-for-discourse/13045)).  There is a great PHP library that handles all of the heavy lifting to make the SSO work called [cviebrock/discourse-php](https://github.com/cviebrock/discourse-php), which this package uses.  This package is loosely based on the work done by [jaewun/discourse-sso-laravel](https://github.com/jaewun/discourse-sso-laravel).\n\n## Build Status\n\n| Branch | Status | Coverage | Code Quality |\n| ------ | :----: | :------: | :----------: |\n| Develop | [![Build Status](https://github.com/spinen/laravel-discourse-sso/workflows/CI/badge.svg?branch=develop)](https://github.com/spinen/laravel-discourse-sso/workflows/CI/badge.svg?branch=develop) | [![Code Coverage](https://scrutinizer-ci.com/g/spinen/laravel-discourse-sso/badges/coverage.png?b=develop)](https://scrutinizer-ci.com/g/spinen/laravel-discourse-sso/?branch=develop) | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/spinen/laravel-discourse-sso/badges/quality-score.png?b=develop)](https://scrutinizer-ci.com/g/spinen/laravel-discourse-sso/?branch=develop) |\n| Master | [![Build Status](https://github.com/spinen/laravel-discourse-sso/workflows/CI/badge.svg?branch=master)](https://github.com/spinen/laravel-discourse-sso/workflows/CI/badge.svg?branch=master) | [![Code Coverage](https://scrutinizer-ci.com/g/spinen/laravel-discourse-sso/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/spinen/laravel-discourse-sso/?branch=master) | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/spinen/laravel-discourse-sso/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/spinen/laravel-discourse-sso/?branch=master) |\n\n## Prerequisite\n\n#### NOTE: If you need to use \u003c PHP 7.2, please stay with version 1.x\n\nAside from Laravel \u003e= 5.5, there is 1 package that is required.\n\n* [\"cviebrock/discourse-php\": \"^0.9.3\",](https://github.com/cviebrock/discourse-php)\n\n## Install\n\nInstall Discourse SSO for Laravel:\n\n```bash\n$ composer require spinen/laravel-discourse-sso\n```\n\nThe package uses the [auto registration feature](https://laravel.com/docs/5.8/packages#package-discovery) of Laravel 5.\n\n## Package Configuration\n\nAll of the configuration values are stored in under a `discourse` key in `config/services.php`.  Here is the array to add...\n\n```php\n    'discourse' =\u003e [\n        // Middleware for the SSO login route to use\n        'middleware' =\u003e ['web', 'auth'],\n\n        // The route's URI that acts as the entry point for Discourse to start the SSO process.\n        // Used by Discourse to route incoming logins.\n        'route' =\u003e 'discourse/sso',\n\n        // Optional domain to link sso route when using SSubdomain Routing\n        'domain' =\u003e null,\n\n        // Secret string used to encrypt/decrypt SSO information,\n        // be sure that it is 10 chars or longer\n        'secret' =\u003e env('DISCOURSE_SECRET'),\n\n        // Disable Discourse from sending welcome message\n        'suppress_welcome_message' =\u003e 'true',\n\n        // Where the Discourse forum lives\n        'url' =\u003e env('DISCOURSE_URL'),\n\n        // Api-specific items\n        // For logging out of Discourse directly, generate an API key as an \"All user key\" and put the key \u0026 user here.\n        // @see https://meta.discourse.org/t/how-to-create-an-api-key-on-the-admin-panel/87383\n        'api' =\u003e [\n            'key' =\u003e env('DISCOURSE_API_KEY'),\n            'user' =\u003e env('DISCOURSE_API_USER'),\n        ],\n\n        // User-specific items\n        // NOTE: The 'email' \u0026 'external_id' are the only 2 required fields\n        'user' =\u003e [\n            // Check to see if the user has forum access \u0026 should be logged in via SSO\n            'access' =\u003e null,\n\n            // Discourse Groups to make sure that the user is part of in a comma-separated string\n            // NOTE: Groups cannot have spaces in their names \u0026 must already exist in Discourse\n            'add_groups' =\u003e null,\n\n            // Boolean for making the user a Discourse admin. Leave null to ignore\n            'admin' =\u003e null,\n\n            // Full path to user's avatar image\n            'avatar_url' =\u003e null,\n\n            // The avatar is cached, so this triggers an update\n            'avatar_force_update' =\u003e false,\n\n            // Content of the user's bio\n            'bio' =\u003e null,\n\n            // Verified email address (see \"require_activation\" if not verified)\n            'email' =\u003e 'email',\n\n            // Unique string for the user that will never change\n            'external_id' =\u003e 'id',\n\n            // Boolean for making user a Discourse moderator. Leave null to ignore\n            'moderator' =\u003e null,\n\n            // Full name on Discourse if the user is new or\n            // if SiteSetting.sso_overrides_name is set\n            'name' =\u003e 'name',\n\n            // Discourse Groups to make sure that the user is *NOT* part of in a comma-separated string.\n            // NOTE: Groups cannot have spaces in their names \u0026 must already exist in Discourse\n            // There is not a way to specify the exact list of groups that a user is in, so\n            // you may want to send the inverse of the 'add_groups'\n            'remove_groups' =\u003e null,\n\n            // If the email has not been verified, set this to true\n            'require_activation' =\u003e false,\n\n            // username on Discourse if the user is new or\n            // if SiteSetting.sso_overrides_username is set\n            'username' =\u003e 'email',\n        ],\n    ],\n```\n\nThe value of the properties for the `user` property can be one of 4 values...\n\n1. `false` -- passed as set to Discourse\n2. `true` -- passed as set to Discourse\n3. `null` -- disables sending property to Discourse\n4. a `string` -- name of a property on the `User` model\n\nYou can then add logic to the `User` model inside of [Accessors](https://laravel.com/docs/master/eloquent-mutators#defining-an-accessor) to provide the values for the properties configured for the user.  For example, if you wanted any user with an email address that matched \"yourdomain.tld\" to be a moderator, then you could set the `moderator` property to a string like `discourse_moderator` and add the following to your `User` model...\n\n```php\n    /**\n     * Is the user a Discourse moderator?\n     *\n     * @param  string  $value\n     * @return boolean\n     */\n    public function getDiscourseModeratorAttribute($value)\n    {\n        return ends_with($this-\u003eemail, \"yourdomain.tld\");\n    }\n```\n\n## Discourse Configuration\n### Settings -\u003e Login\nThese are the configs we have under `Settings -\u003e Login`. If a setting isn't listed, then ours is set to the default value.\n\n| **Setting**              | **Value**                                                |\n|--------------------------|----------------------------------------------------------|\n| login required           | true                                                     |\n| enable sso               | true                                                     |\n| sso url                  | Our Laravel's SSO route (FQDN)                           |\n| sso secret               | Our SSO secret key                                       |\n| sso overrides bio        | true                                                     |\n| sso overrides email      | true                                                     |\n| sso overrides username   | true                                                     |\n| sso overrides name       | true                                                     |\n| sso overrides avatar     | true                                                     |\n| sso not approved url     | Our Laravel homepage (same as `url` in `config/app.php`) |\n| hide email address taken | true                                                     |\n_______________________________________________________________________\n\n\n### Settings -\u003e Users\nThese are the configs we have under `Settings -\u003e Users`. If a setting isn't listed, then ours is set to the default value.\n\n| **Setting**                               | **Value**                                                |\n|-------------------------------------------|----------------------------------------------------------|\n| reserved usernames                        | We added our client's company name                       |\n| min password length                       | 8                                                        |\n| min admin password length                 | 8                                                        |\n| email editable                            | false                                                    |\n| logout redirect                           | Our Laravel homepage (same as `url` in `config/app.php`) |\n| purge unactivated users grace period days | 30                                                       |\n| hide user profiles from public            | true                                                     |\n_______________________________________________________________________\n\n## Logging out the Discourse User\n\nThere's a listener in `src/Listeners/LogoutDiscourseUser.php` that will automatically log out the user from Discourse when certain events are fired. To use the Listener, [you need to register the event](https://laravel.com/docs/master/events#registering-events-and-listeners) in the `$listen` array in your `EventServiceProvider`.\n\nWhen a Laravel `User` logs out, to log out their Discourse session Simply add the Laravel `Logout` event \u0026 the `LogoutDiscourseUser` listener in that `$listen` array. If you want to log out Discourse users on a Laravel `User` being deleted or disabled, make your own event class and register it the same way.\n\n### Example\n\n```php\n    protected $listen = [\n        \\Illuminate\\Auth\\Events\\Logout::class =\u003e [\n            \\Spinen\\Discourse\\Listeners\\LogoutDiscourseUser::class,\n        ],\n        \\App\\Events\\YourCustomEvent::class =\u003e [\n            \\Spinen\\Discourse\\Listeners\\LogoutDiscourseUser::class,\n        ],\n    ];\n```\n\n### Laravel 11\n\nIn Laravel 11, the use of the `EventServiceProvider` is discouraged and events [should be registered in the `AppServiceProvider`](https://laravel.com/docs/11.x/events#manually-registering-events).\n\nTherefore, the implementation is slightly different, and it should be registered within the `boot` method of the `AppServiceProvider` as per the example below.\n\n```php\n    /**\n     * Bootstrap any application services.\n     */\n    public function boot(): void\n    {\n        Event::listen(\n            \\Illuminate\\Auth\\Events\\Logout::class,\n            \\Spinen\\Discourse\\Listeners\\LogoutDiscourseUser::class\n        );\n    }\n```\n\n## Left to do\n\n* badges for user\n* support for [`custom_fields`](https://meta.discourse.org/t/custom-user-fields-for-plugins/14956)\n* failed login redirect\n* `return_paths` support\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspinen%2Flaravel-discourse-sso","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspinen%2Flaravel-discourse-sso","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspinen%2Flaravel-discourse-sso/lists"}