Adds a login button on Discourse which allows logging in using a Silverstripe site’s user account.
On Silverstripe site:
Install https://github.com/IanSimpson/ss-oauth2-server on Silverstripe site.
config.json
:
"guzzlehttp/psr7": "2.1.0 as 1.4"
IanSimpson\\OAuth2\\OauthServerController:
privateKey: 'private.key'
publicKey: 'public.key'
encryptionKey: 'INSERTKEYHERE'
c. dev/build
d. In Site Config, create a Client
Redirect URI: http://DISCOURSE_HOST/auth/oauth2_basic/callback
On Discourse:
Docs: https://github.com/discourse/discourse-oauth2-basic#part-2-configuring-the-json-user-endpoint
Still TODO. Ideally create a Silverstripe module for this.
Create an endpoint on Silverstripe site that returns member details as JSON.
Get member object using $member = IanSimpson\\OAuth2\\OauthServerController::getMember($this);
to ensure that token is authenticated.
Output $member
details, e.g.
{
"id": 123,
"name": "John Smith",
"email": "[email protected]",
}
Add URL of endpoint to Discourse > Settings > Login > oauth2 user json url
Add JSON paths to Discourse > Settings > Login (based on JSON format) e.g.
Can only send through the following to Discourse:
Cannot pass through other details, such as Discourse groups to assign member to.
Pre-filled signup form is presented in Discourse allowing details to change imported details.
(But Silverstripe account still linked to this account for future logins.)
Disable enable local logins in Discourse so that that Log In / Sign Up buttons go straight to Silverstripe login, and don’t display Discourse login modal.
To log out of Silverstripe after use logs out of Discourse:
http://example.com/Security/logout?BackURL=/home