Commit 160a6a7e authored by Jon Yu's avatar Jon Yu
Browse files

Condense auth check, fix settings issue

parent 4fa3bda3
Pipeline #17739 passed with stage
in 14 seconds
import unicodedata
from django.conf import settings
from mozilla_django_oidc.auth import OIDCAuthenticationBackend
def using_oidc_auth():
return (
settings.OIDC_RP_CLIENT_ID and
settings.OIDC_RP_CLIENT_SECRET and
settings.OIDC_OP_AUTHORIZATION_ENDPOINT and
settings.OIDC_OP_TOKEN_ENDPOINT and
settings.OIDC_OP_USER_ENDPOINT
)
def generate_username(email):
return unicodedata.normalize('NFKC', email).split('@')[0]
......
from django.urls import reverse
from django.conf import settings
from oidc_auth.utils import using_oidc_auth
from oidc_auth.auth import using_oidc_auth
def login_url(request):
......
from django.conf.urls import url
from django.urls import include, path
from oidc_auth.utils import using_oidc_auth
from oidc_auth.auth import using_oidc_auth
urlpatterns = [
url(r'^oidc/', include('mozilla_django_oidc.urls')),
......
from django.conf import settings
def using_oidc_auth():
return (
settings.OIDC_RP_CLIENT_ID and
settings.OIDC_RP_CLIENT_SECRET and
settings.OIDC_OP_AUTHORIZATION_ENDPOINT and
settings.OIDC_OP_TOKEN_ENDPOINT and
settings.OIDC_OP_USER_ENDPOINT
)
......@@ -12,7 +12,6 @@ https://docs.djangoproject.com/en/3.0/ref/settings/
import os
import dj_database_url
from oidc_auth.utils import using_oidc_auth
def str_to_bool(val):
......@@ -130,7 +129,8 @@ OIDC_USERNAME_ALGO = 'oidc_auth.auth.generate_username'
OIDC_RP_SCOPES = 'openid email profile'
OIDC_CREATE_USER = str_to_bool(os.getenv('OIDC_CREATE_USER', 'on'))
if using_oidc_auth():
if (OIDC_RP_CLIENT_ID and OIDC_RP_CLIENT_SECRET and OIDC_OP_AUTHORIZATION_ENDPOINT
and OIDC_OP_TOKEN_ENDPOINT and OIDC_OP_USER_ENDPOINT):
EXTRA_APPS += ['mozilla_django_oidc']
AUTHENTICATION_BACKENDS += ['oidc_auth.auth.UMichOIDCBackend']
MIDDLEWARE += ['mozilla_django_oidc.middleware.SessionRefresh']
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment