Skip to content

Commit

Permalink
linter
Browse files Browse the repository at this point in the history
  • Loading branch information
challet committed Mar 19, 2021
1 parent fcadbee commit 535c92f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
1 change: 0 additions & 1 deletion djangosaml2idp/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from django.core.exceptions import ImproperlyConfigured
from django.http import HttpRequest
from django.utils.module_loading import import_string
from saml2.config import IdPConfig


def get_callable(path: Union[Callable, str]) -> Callable:
Expand Down
7 changes: 4 additions & 3 deletions djangosaml2idp/idp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
from saml2.config import IdPConfig
from saml2.metadata import entity_descriptor
from saml2.server import Server
from typing import Callable, Dict, Optional, TypeVar, Union
from typing import Callable, Dict, Optional, Union

from .conf import get_callable, get_config


class IDP:
""" Access point for the IDP Server instance
"""
_server_instances: Dict[str, Server] = {}

@classmethod
def construct_metadata(cls, idp_conf: dict, request: Optional[HttpRequest] = None, with_local_sp: bool = True) -> IdPConfig:
""" Get the config including the metadata for all the configured service providers. """
Expand Down Expand Up @@ -55,7 +56,7 @@ def load(cls, request: Optional[HttpRequest] = None, config_loader_path: Optiona
@classmethod
def flush(cls):
cls._server_instances = {}

@classmethod
def metadata(cls, request: Optional[HttpRequest] = None, config_loader_path: Optional[Union[Callable, str]] = None) -> str:
""" Get the IDP metadata as a string. """
Expand Down
10 changes: 4 additions & 6 deletions djangosaml2idp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@
from django.views.decorators.http import require_http_methods
from saml2 import BINDING_HTTP_POST, BINDING_HTTP_REDIRECT
from saml2.authn_context import PASSWORD, AuthnBroker, authn_context_class_ref
from saml2.config import IdPConfig
from saml2.ident import NameID
from saml2.saml import NAMEID_FORMAT_UNSPECIFIED
from saml2.server import Server
from saml2.s_utils import UnknownSystemEntity

from .error_views import error_cbv
from .idp import IDP
Expand Down Expand Up @@ -149,16 +147,16 @@ def build_authn_response(user: User, authn, resp_args, service_provider: Service

class IdPHandlerViewMixin:
config_loader_path = getattr(settings, 'SAML_IDP_CONFIG_LOADER', None)

def get_config_loader_path(self, request: HttpRequest):
return self.config_loader_path

def get_idp_server(self, request: HttpRequest) -> Server:
return IDP.load(request, self.get_config_loader_path(request))

def get_idp_metadata(self, request: HttpRequest) -> str:
return IDP.metadata(request, self.get_config_loader_path(request))

""" Contains some methods used by multiple views """
def render_login_html_to_string(self, context=None, request=None, using=None):
""" Render the html response for the login action. Can be using a custom html template if set on the view. """
Expand Down

0 comments on commit 535c92f

Please sign in to comment.