Skip to content

Commit

Permalink
updated code based on Michaels suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesstottmoj committed Apr 9, 2024
1 parent 43cfba6 commit 1f281e4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
1 change: 0 additions & 1 deletion controlpanel/frontend/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
urlpatterns = [
path("", views.IndexView.as_view(), name="index"),
path("oidc/entraid/auth/", views.EntraIdAuthView.as_view(), name="entraid-auth"),
path("oidc/callback/", views.EntraOIDCAuthenticationCallbackView.as_view(), name="entra_callback"),
path("oidc/logout/", views.LogoutView.as_view(), name="oidc_logout"),
path("datasources/", views.AdminBucketList.as_view(), name="list-all-datasources"),
path(
Expand Down
2 changes: 1 addition & 1 deletion controlpanel/frontend/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# First-party/Local
from controlpanel.frontend.views.accessibility import Accessibility
from controlpanel.frontend.views.auth import EntraIdAuthView, EntraOIDCAuthenticationCallbackView
from controlpanel.frontend.views.auth import EntraIdAuthView

# isort: off
from controlpanel.frontend.views.app import (
Expand Down
15 changes: 0 additions & 15 deletions controlpanel/frontend/views/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from django.http import HttpResponseRedirect, Http404
from django.urls import reverse
from django.views import View
from mozilla_django_oidc.views import OIDCAuthenticationCallbackView

# First-party/Local
from controlpanel.oidc import OIDCLoginRequiredMixin, oauth
Expand Down Expand Up @@ -63,17 +62,3 @@ def update_user(self, token):
email = token["userinfo"]["email"]
self.request.user.justice_email = email
self.request.user.save()


class EntraOIDCAuthenticationCallbackView(OIDCAuthenticationCallbackView):
"""
This view is used to redirect to the index page if the user has not
authenticated with their justice email.
"""
def get(self, request):
response = super().get(request)

if self.user.justice_email is not None:
return response

return HttpResponseRedirect(reverse("index"))
9 changes: 9 additions & 0 deletions controlpanel/oidc.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,22 @@ def verify_claims(self, claims):


class StateMismatchHandler(OIDCAuthenticationCallbackView):

def get(self, *args, **kwargs):
try:
return super().get(*args, **kwargs)
except SuspiciousOperation as e:
log.warning(f"Caught {e}: redirecting to login")
return HttpResponseRedirect(settings.LOGIN_REDIRECT_URL_FAILURE)

@property
def success_url(self):

if not self.user.justice_email:
return reverse("index")

return super().success_url


def logout(request):
params = urlencode(
Expand Down

0 comments on commit 1f281e4

Please sign in to comment.