Skip to main content

Discourse Single-Sign-on (DSSO) provider client to connect your Django project to a Discourse Single-Sign-On provider server.

See: https://meta.discourse.org/t/official-single-sign-on-for-discourse-sso/

Example usage:

  • Add kleides_dssoclient to INSTALLED_APPS.

  • Create a custom DssoLoginBackend, for example:

    from kleides_dssoclient.backends import DssoLoginBackend
    
    class MyProjectDssoLoginBackend(DssoLoginBackend):
        """
        DssoLoginBackend that rejects anyone without is_superuser, and that
        sets all mapped variables on the newly created User object.
        """
        def authenticate(self, dsso_mapping):
            """
            Check that user is a superuser and pass along to DssoLoginBackend.
            """
            if dsso_mapping.get('is_superuser') not in ('True', 'true', '1'):
                return None
    
            return super(MyProjectDssoLoginBackend, self).authenticate(
                dsso_mapping)
    
        def configure_user(self, user, dsso_mapping):
            """
            We expect username, email, is_superuser in the dsso_mapping.
            """
            user = (
                super(MyProjectDssoLoginBackend, self)
                .configure_user(user, dsso_mapping))
    
            user.email = dsso_mapping.get('email', '')
            is_superuser = (
                dsso_mapping.get('is_superuser') in ('True', 'true', '1'))
            user.is_staff = is_superuser
            user.is_superuser = is_superuser
    
            user.save()
            return user
  • Add this to the Django settings:

    AUTHENTICATION_BACKENDS = (  # the only backend needed
        'myproject.backends.MyProjectDssoLoginBackend',
    )
    MIDDLEWARE_CLASSES += (
        'kleides_dssoclient.middleware.DssoLoginMiddleware',
    )
    KLEIDES_DSSO_ENDPOINT = 'https://DSSOSERVER/sso/'
    KLEIDES_DSSO_SHARED_KEY = 'oh-sso-very-very-secret'

Changes

v0.8 - 2020-09-28

  • Allow using the Dsso backend as a mixin.

v0.7 - 2019-07-16

  • Allow bypassing the middleware by setting KLEIDES_DSSO_ENDPOINT to None.

v0.6 - 2019-03-06

  • Add request arg to DssoLoginBackend for Django 2.1.

v0.5 - 2019-03-06

  • Add logging to help investigate problems.

v0.3 - 2018-12-18

  • Add support for Django 1.10 style middleware.

  • Check Django version for is_authenticated usage.

v0.2 - 2018-11-19

  • Replace sso_mapping with dsso_mapping in authenticate argument list.

v0.1 - 2018-11-16

  • Initial release.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kleides_dssoclient-0.8.tar.gz (19.6 kB view details)

Uploaded Source

File details

Details for the file kleides_dssoclient-0.8.tar.gz.

File metadata

  • Download URL: kleides_dssoclient-0.8.tar.gz
  • Upload date:
  • Size: 19.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.2

File hashes

Hashes for kleides_dssoclient-0.8.tar.gz
Algorithm Hash digest
SHA256 fbb5cc8412116ad993528ddeaeab815a0bb8d8f1e33167b4d8e96d2e5517a5cf
MD5 9560254883c2f021187e84b44a999a02
BLAKE2b-256 7f66bc1bc8ac0c723d5525df3d9403ab4cefb8f250beaee7939e05d7131b7621

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page