Package: selfauth
Self OpenID ClientDjango plugin that replaces the standard Django user model and replaces it with Self Street OpenID integration.Note: This project is open source but currently only being used within Column Street. If you would like to integrate Self logging into your website/app/project please reach out to us so we can discuss.UseThis package is a thin layer on top of themozilla-django-oidcproject, therefore integration is very similar.1. Register Application with SelfEither contact an admin, or initiate it via the administrator board in Self.2. Install Packagepip install selfauth3. Add & Modify SettingsThe following settings need to be initialized. Inside yourINSTALLED_APPSmake sure to addmozilla_django_oidcandselfauthright afterdjango.contrib.auth.INSTALLED_APPS=[...,"django.contrib.auth","mozilla_django_oidc","selfauth",...]At the end of your settings file you can then add the following:# =======================================================================================================# Self Street# Custom User Model# https://docs.djangoproject.com/en/3.1/topics/auth/customizing/#substituting-a-custom-user-model# This custom user model is used with the OIDC backend to ensure Self and Meta communicate properly.AUTH_USER_MODEL="selfauth.User"# Authentication Backend# https://docs.djangoproject.com/en/3.1/topics/auth/customizing/#specifying-authentication-backends# Must be modified so that the OpenID plugin can automatically create users# based on the login of the user from Self. We use a custom authentication so that# we take care of user updates and uniqueness.AUTHENTICATION_BACKENDS=("selfauth.auth.SelfAuthenticationBackend",)# OpenID# https://mozilla-django-oidc.readthedocs.io/en/stable/installation.html#choose-the-appropriate-algorithm# These are settings related to the OpenID Connect Client.# Client ID and SecretOIDC_RP_CLIENT_ID=""OIDC_RP_CLIENT_SECRET=""# Server EndpointsOIDC_OP_ENDPOINT="https://self.st"OIDC_OP_JWKS_ENDPOINT=OIDC_OP_ENDPOINT+"/o/jwks/"OIDC_OP_AUTHORIZATION_ENDPOINT=OIDC_OP_ENDPOINT+"/o/authorize/"OIDC_OP_TOKEN_ENDPOINT=OIDC_OP_ENDPOINT+"/o/token/"OIDC_OP_USER_ENDPOINT=OIDC_OP_ENDPOINT+"/o/userinfo/"# Scopes# https://github.com/mozilla/mozilla-django-oidc/blob/master/mozilla_django_oidc/auth.py#L84# These are the default scopes that any OpenID Client with Self has access to. Add any extra if you have.OIDC_RP_SCOPES="openid profile email"# Custom Test Page# Enables test webpage at self.st/login.AUTH_TEST=TrueAUTH_TEST_PATH="login"# =======================================================================================================Make sure to modify the following varaibles:OIDC_RP_CLIENT_ID: Client ID given and generated by Self.OIDC_RP_CLIENT_SECRET: Client secret given and generated by Self. Recommended to be passed as an env variable.4. Create Migrationspython manage.py makemigrations
python manage.py migrate5. RoutesLogging can be done found via the routeroidc_authentication_init, and logout viaoidc_logout. This is defined in themozilla-django-oidcdocshere. Make sure to set the routes:fromdjango.urlsimportpath,includeurlpatterns=[...path("",include("selfauth.urls")),]6. TestingIf you would like to test the framework, enabling theAUTH_TESTvariable will allow you to access the test page in theAUTH_TEST_PATHpath. In the case above the test page will be inhttp://example.com/login.