sanic_jwt/authentication.py
async def _verify(
        self,
        request,
        return_payload=False,
        verify=True,
        raise_missing=False,
        request_args=None,
        request_kwargs=None,
        *args,
        **kwargs,
    ):
        """
        Verify that a request object is authenticated.
        """
        try:
            token = self._get_token(request)
            is_valid = True
            reason = None
        except (
            exceptions.MissingAuthorizationCookie,
            exceptions.MissingAuthorizationQueryArg,
            exceptions.MissingAuthorizationHeader,
        ) as e:
            token = None
            is_valid = False
            reason = list(e.args)
            status = e.status_code if self.config.debug() else 401

            if raise_missing:
                if not self.config.debug():
                    e.status_code = 401
                raise e

        if token:
            try:
                payload = await self._decode(token, verify=verify)
            except (
                jwt.exceptions.ExpiredSignatureError,
                jwt.exceptions.InvalidIssuerError,
                jwt.exceptions.ImmatureSignatureError,
                jwt.exceptions.InvalidIssuedAtError,
                jwt.exceptions.InvalidAudienceError,
                InvalidVerificationError,
                InvalidCustomClaimError,
            ) as e:
                # Make sure that the reasons all end with '.' for consistency
                reason = [
                    x if x.endswith(".") else "{}.".format(x)
                    for x in list(e.args)
                ]
                payload = None
                status = 401
                is_valid = False
            except jwt.exceptions.DecodeError as e:
                self._reasons = e.args
                # Make sure that the reasons all end with '.' for consistency
                reason = (
                    [
                        x if x.endswith(".") else "{}.".format(x)
                        for x in list(e.args)
                    ]
                    if self.config.debug()
                    else "Auth required."
                )
                logger.debug(e.args)
                is_valid = False
                payload = None
                status = 400 if self.config.debug() else 401
        else:
            payload = None

        if return_payload:
            return payload

        status = 200 if is_valid else status

        return is_valid, status, reason

        Verify that a request object is authenticated.
        
Verify that a request object is authenticated.
Verify that a request object is authenticated .
async def _verify(
        self,
        request,
        return_payload=False,
        verify=True,
        raise_missing=False,
        request_args=None,
        request_kwargs=None,
        *args,
        **kwargs,
    ):
        try:
            token = self._get_token(request)
            is_valid = True
            reason = None
        except (
            exceptions.MissingAuthorizationCookie,
            exceptions.MissingAuthorizationQueryArg,
            exceptions.MissingAuthorizationHeader,
        ) as e:
            token = None
            is_valid = False
            reason = list(e.args)
            status = e.status_code if self.config.debug() else 401
            if raise_missing:
                if not self.config.debug():
                    e.status_code = 401
                raise e
        if token:
            try:
                payload = await self._decode(token, verify=verify)
            except (
                jwt.exceptions.ExpiredSignatureError,
                jwt.exceptions.InvalidIssuerError,
                jwt.exceptions.ImmatureSignatureError,
                jwt.exceptions.InvalidIssuedAtError,
                jwt.exceptions.InvalidAudienceError,
                InvalidVerificationError,
                InvalidCustomClaimError,
            ) as e:
                reason = [
                    x if x.endswith(".") else "{}.".format(x)
                    for x in list(e.args)
                ]
                payload = None
                status = 401
                is_valid = False
            except jwt.exceptions.DecodeError as e:
                self._reasons = e.args
                reason = (
                    [
                        x if x.endswith(".") else "{}.".format(x)
                        for x in list(e.args)
                    ]
                    if self.config.debug()
                    else "Auth required."
                )
                logger.debug(e.args)
                is_valid = False
                payload = None
                status = 400 if self.config.debug() else 401
        else:
            payload = None
        if return_payload:
            return payload
        status = 200 if is_valid else status
        return is_valid, status, reason
async def _verify ( self , request , return_payload = False , verify = True , raise_missing = False , request_args = None , request_kwargs = None , * args , ** kwargs , ) : try : token = self . _get_token ( request ) is_valid = True reason = None except ( exceptions . MissingAuthorizationCookie , exceptions . MissingAuthorizationQueryArg , exceptions . MissingAuthorizationHeader , ) as e : token = None is_valid = False reason = list ( e . args ) status = e . status_code if self . config . debug ( ) else 401 if raise_missing : if not self . config . debug ( ) : e . status_code = 401 raise e if token : try : payload = await self . _decode ( token , verify = verify ) except ( jwt . exceptions . ExpiredSignatureError , jwt . exceptions . InvalidIssuerError , jwt . exceptions . ImmatureSignatureError , jwt . exceptions . InvalidIssuedAtError , jwt . exceptions . InvalidAudienceError , InvalidVerificationError , InvalidCustomClaimError , ) as e : reason = [ x if x . endswith ( "." ) else "{}." . format ( x ) for x in list ( e . args ) ] payload = None status = 401 is_valid = False except jwt . exceptions . DecodeError as e : self . _reasons = e . args reason = ( [ x if x . endswith ( "." ) else "{}." . format ( x ) for x in list ( e . args ) ] if self . config . debug ( ) else "Auth required." ) logger . debug ( e . args ) is_valid = False payload = None status = 400 if self . config . debug ( ) else 401 else : payload = None if return_payload : return payload status = 200 if is_valid else status return is_valid , status , reason
Verify that a request object is authenticated.
Verify that a request object is authenticated .
"""
        Verify that a request object is authenticated.
        """ # Make sure that the reasons all end with '.' for consistency # Make sure that the reasons all end with '.' for consistency
self
request
return_payload
verify
raise_missing
request_args
request_kwargs