Esempio n. 1
0
    def __check_classes(self):
        """
        Check if any of the default classes (`Authentication`, `Configuration`
        and / or `Responses`) have been overwitten and if they're still valid
        """
        # msg took from BaseAuthentication
        msg = "Sanic JWT was not initialized properly. It did not " "received an instance of {}"
        if not issubclass(self.authentication_class, Authentication):
            raise exceptions.InitializationFailure(
                message=msg.format("Authentication"))

        if not issubclass(self.configuration_class, Configuration):
            raise exceptions.InitializationFailure(
                message=msg.format("Configuration"))

        if not issubclass(self.responses_class, Responses):
            raise exceptions.InitializationFailure(
                message=msg.format("Responses"))
Esempio n. 2
0
    def __get_app(instance, app=None):
        if isinstance(instance, Sanic):
            return instance

        elif isinstance(instance, Blueprint):
            if app is not None:
                return app
            message = "Sanic JWT was not initialized properly. When "
            "instantiating on a sanic.Blueprint you must pass your app "
            "instance: Initialize(bp, app=app, ...)"
            raise exceptions.InitializationFailure(message=message)

        raise exceptions.InitializationFailure