Shibboleth / SAML / SSO -- Working Implementation for Higher Ed

AI-generated summary

nmagee describes how their campus, part of the InCommon federation, successfully integrated Shibboleth SAML authentication with Discourse using Discourse’s built-in SSO provider. After struggling to connect Shibboleth directly to Discourse, they created a separate Shibboleth-protected SSO endpoint — a simple PHP page — that handles authentication and redirects users back to Discourse with properly signed SSO data. The script verifies the SSO payload, extracts user attributes (uid, eppn, sn, givenname) from $_SERVER, reassembles the payload with the nonce, encodes it, and generates a correct HMAC-SHA256 signature — noting that a key mistake was signing the urlencoded payload instead of the base64-encoded one. Once corrected, the integration worked flawlessly. The solution is adaptable to other languages like Python or Ruby, as long as they can run in a Shibboleth-compatible web environment. nmagee praises Discourse’s SSO feature for its ease of use, especially how it automatically stubs out new user accounts using basic user data passed via SSO.

Our campus, like many others around the US, is part of the InCommon federation, and shares a federated SAML authentication pool. So, while IT services had straightforward documentation for how to plug Shibboleth into Apache2 to protect a “regular” website, it was very unclear how to connect that with Discourse.

After banging our heads against it for awhile, the clear (and now obvious) solution was to create a separate SSO endpoint that is Shibboleth-protected, and point Discourse to that using the built-in SSO provider.

Instructions for SSO are here.

A few details:

  • The SSO endpoint we created is a single page of PHP, in a directory that requires Shibboleth authentication. Since our Discourse app is to be available to the entire university, any scoping is done at our IdP provider and not on our end.
  • It parses the payload and signature in the query string to verify, unpack, and get the nonce.
  • Then gets a few bits about the user via $_SERVER['value'] values (uid, eppn, sn, givenname) to create the new payload.
  • It then reassembles a new payload, with nonce, encodes it and generates a new hash, then HTTP GETs the user back to the right endpoint on our Discourse site.
  • The only hangup was that I was generating the HMAC-SHA256 signature on the urlencoded payload and not the base64 payload. Once I saw that mistake and signed the latter, it worked perfectly.

You could do this in PHP, Python, Ruby, anything that can run simply in a web environment that Shibboleth plays nicely with.

The Discourse team did a good job on this feature – I like that you can pass basic bits of user data to the SSO and a new account is stubbed out without any fuss.

9 Likes