With this library you can use Discourse as a SSO provider for your Spring (Boot) application.
The Discourse SSO provider is described on meta.discourse.org.
Discourse SSO provider must be enabled and configured with a (site specific) secret inside the admin settings.
- Redirect to
DISCOURSE_ROOT_URL/session/sso_provider?sso=PAYLOAD&sig=SIGNATURE
, wheresso
is a Base64 & URL encoded payload consisting of anonce
and areturn_sso_url
sig
is a HMAC-SHA256 signature of the Base64 encoded payload
- Login procedure or instant redirect from Discourse to the
return_sso_url
- Validate and process response parameters
sso
andsig
- Compute signature of
sso
and compare withsig
- Validate
sso.nonce
- Create Spring Security Authentication from
sso
payload
- Compute signature of
This project comes with AutoConfiguration support.
- Add
spring-discourse-sso-autoconfigure
dependency:
<dependency>
<groupId>org.ollide</groupId>
<artifactId>spring-discourse-sso-autoconfigure</artifactId>
<version>CURRENT_RELEASE</version>
</dependency>
- Configure
spring-discourse-sso
inside yourapplication.properties
:
discourse.sso.secret=***************
discourse.sso.discourseUrl=https://<<DISCOURSE_DOMAIN>>/session/sso_provider
-
Optional customizations:
-
The application's login endpoint defaults to
/login/discourse
and can be customized with the propertydiscourse.sso.loginPath
-
The
return_sso_url
defaults to/login/discourse/success
and can be customized with the propertydiscourse.sso.returnPath
-
If you don't want to use AutoConfiguration support, you must use
spring-discourse-sso
directly:
<dependency>
<groupId>org.ollide</groupId>
<artifactId>spring-discourse-sso</artifactId>
<version>CURRENT_RELEASE</version>
</dependency>
The key components to look for are:
DiscourseSigner
: Takes the SSO secret, signs & validates the payloadsSsoEndpoint
: Triggers the redirect to DiscourseDiscourseSsoVerificationFilter
: ServletFilter for the response, validates and attempts authenticationDiscoursePrincipal
: The Principal that can be accessed through Spring's SecurityContext after successful authentication