Make it easier to change AuthorizeEndpoint and Client

To make it easier to change the AuthorizeEndpoint and Client we set them as class variables. Then people inheriting from the view are able to easily change them. In my personal case this helps with skipping consent more explicitly as defined in issue https://github.com/juanifioren/django-oidc-provider/issues/278
This commit is contained in:
Bono de Visser 2018-09-14 11:21:57 +02:00
parent 0effc32be2
commit 69b793a363
2 changed files with 5 additions and 3 deletions

View file

@ -37,6 +37,7 @@ logger = logging.getLogger(__name__)
class AuthorizeEndpoint(object): class AuthorizeEndpoint(object):
_allowed_prompt_params = {'none', 'login', 'consent', 'select_account'} _allowed_prompt_params = {'none', 'login', 'consent', 'select_account'}
client_class = Client
def __init__(self, request): def __init__(self, request):
self.request = request self.request = request
@ -86,7 +87,7 @@ class AuthorizeEndpoint(object):
def validate_params(self): def validate_params(self):
# Client validation. # Client validation.
try: try:
self.client = Client.objects.get(client_id=self.params['client_id']) self.client = self.client_class.objects.get(client_id=self.params['client_id'])
except Client.DoesNotExist: except Client.DoesNotExist:
logger.debug('[Authorize] Invalid client identifier: %s', self.params['client_id']) logger.debug('[Authorize] Invalid client identifier: %s', self.params['client_id'])
raise ClientIdError() raise ClientIdError()

View file

@ -61,9 +61,10 @@ OIDC_TEMPLATES = settings.get('OIDC_TEMPLATES')
class AuthorizeView(View): class AuthorizeView(View):
def get(self, request, *args, **kwargs): authorize_endpoint_class = AuthorizeEndpoint
authorize = AuthorizeEndpoint(request) def get(self, request, *args, **kwargs):
authorize = self.authorize_endpoint_class(request)
try: try:
authorize.validate_params() authorize.validate_params()