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/sources/oauth/views/dispatcher.py

23 lines
782 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
2019-10-07 14:33:48 +00:00
from passbook.sources.oauth.models import OAuthSource
from passbook.sources.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 Source by slug and forward request"""
2019-12-31 11:51:16 +00:00
slug = kwargs.get("source_slug", None)
2018-11-11 12:41:48 +00:00
if not slug:
raise Http404
source = get_object_or_404(OAuthSource, slug=slug)
view = MANAGER.find(source, kind=RequestKind(self.kind))
return view.as_view()(*args, **kwargs)