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/oauth_client/views/dispatcher.py
2018-11-11 13:41:48 +01:00

23 lines
787 B
Python

"""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.oauth_client.models import OAuthSource
from passbook.oauth_client.source_types.manager import MANAGER, RequestKind
class DispatcherView(View):
"""Dispatch OAuth Redirect/Callback views to their proper class based on URL parameters"""
kind = ''
def dispatch(self, *args, **kwargs):
"""Find Source by slug and forward request"""
slug = kwargs.get('source_slug', None)
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)