This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
authentik/passbook/channels/in_oauth/views/dispatcher.py

23 lines
784 B
Python
Raw Normal View History

2018-11-11 12:41:48 +00:00
"""Dispatch OAuth views to respective views"""
from django.http import Http404
from django.shortcuts import get_object_or_404
from django.views import View
from passbook.channels.in_oauth.models import OAuthInlet
from passbook.channels.in_oauth.types.manager import MANAGER, RequestKind
2018-11-11 12:41:48 +00:00
class DispatcherView(View):
"""Dispatch OAuth Redirect/Callback views to their proper class based on URL parameters"""
2019-12-31 11:51:16 +00:00
kind = ""
2018-11-11 12:41:48 +00:00
def dispatch(self, *args, **kwargs):
"""Find Inlet by slug and forward request"""
slug = kwargs.get("inlet_slug", None)
2018-11-11 12:41:48 +00:00
if not slug:
raise Http404
inlet = get_object_or_404(OAuthInlet, slug=slug)
view = MANAGER.find(inlet, kind=RequestKind(self.kind))
2018-11-11 12:41:48 +00:00
return view.as_view()(*args, **kwargs)