How to use the jwt.exceptions.MissingRequiredClaimError function in jwt

To help you get started, we’ve selected a few jwt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yunojuno / django-request-token / tests / test_admin.py View on Github external
def test_jwt(self):
        token = RequestToken(id=1, scope="foo").save()
        admin = RequestTokenAdmin(RequestToken, None)
        self.assertEqual(admin.jwt(token), token.jwt())

        token = RequestToken()
        self.assertRaises(MissingRequiredClaimError, token.jwt)
        self.assertEqual(admin.jwt(token), None)
github jpadilla / django-rest-framework-jwt / tests / test_utils.py View on Github external
def test_fail_issuer_missing(self):
        payload = utils.jwt_payload_handler(self.user)
        del payload['iss']
        token = utils.jwt_encode_handler(payload)
        with self.assertRaises(jwt.exceptions.MissingRequiredClaimError):
            utils.jwt_decode_handler(token)
github jpadilla / pyjwt / tests / test_api_jwt.py View on Github external
def test_decode_should_raise_error_if_iat_required_but_not_present(
        self, jwt
    ):
        payload = {
            "some": "payload",
            # iat not present
        }
        token = jwt.encode(payload, "secret")

        with pytest.raises(MissingRequiredClaimError) as exc:
            jwt.decode(token, "secret", options={"require_iat": True})

        assert exc.value.claim == "iat"
github NovemberOscar / Flask-GraphQL-Auth / auge / api_auge.py View on Github external
token = token.decode()

    bheader, bpayload, bsignature = token.split('.')
    header = json.loads(bheader.decode())
    payload = json.loads(bpayload.decode())

    # claim check
    payload_keys = list(payload.keys())
    if 'jti' not in payload_keys:
        raise exceptions.MissingRequiredClaimError('jti')
    if 'exp' not in payload_keys:
        raise exceptions.MissingRequiredClaimError('exp')
    if 'type' not in payload_keys:
        raise exceptions.MissingRequiredClaimError('type')
    if 'identity' not in payload_keys:
        raise exceptions.MissingRequiredClaimError('identity')
    if 'iat' not in payload_keys:
        raise exceptions.MissingRequiredClaimError('iat')

    # signature compare
    if bsignature is not make_signature(bheader, bpayload, secret):
        raise exceptions.InvalidSignatureError('Invalid token signature')

    # expire check
    if payload['exp'] > int(time.time()):
        raise exceptions.ExpiredSignatureError('Token has been expired')

    return header, payload
github NovemberOscar / Flask-GraphQL-Auth / auge / api_auge.py View on Github external
def decode_token(token, secret):

    if type(token) is bytes:
        token = token.decode()

    bheader, bpayload, bsignature = token.split('.')
    header = json.loads(bheader.decode())
    payload = json.loads(bpayload.decode())

    # claim check
    payload_keys = list(payload.keys())
    if 'jti' not in payload_keys:
        raise exceptions.MissingRequiredClaimError('jti')
    if 'exp' not in payload_keys:
        raise exceptions.MissingRequiredClaimError('exp')
    if 'type' not in payload_keys:
        raise exceptions.MissingRequiredClaimError('type')
    if 'identity' not in payload_keys:
        raise exceptions.MissingRequiredClaimError('identity')
    if 'iat' not in payload_keys:
        raise exceptions.MissingRequiredClaimError('iat')

    # signature compare
    if bsignature is not make_signature(bheader, bpayload, secret):
        raise exceptions.InvalidSignatureError('Invalid token signature')

    # expire check
    if payload['exp'] > int(time.time()):
        raise exceptions.ExpiredSignatureError('Token has been expired')
github NovemberOscar / Flask-GraphQL-Auth / auge / api_auge.py View on Github external
def decode_token(token, secret):

    if type(token) is bytes:
        token = token.decode()

    bheader, bpayload, bsignature = token.split('.')
    header = json.loads(bheader.decode())
    payload = json.loads(bpayload.decode())

    # claim check
    payload_keys = list(payload.keys())
    if 'jti' not in payload_keys:
        raise exceptions.MissingRequiredClaimError('jti')
    if 'exp' not in payload_keys:
        raise exceptions.MissingRequiredClaimError('exp')
    if 'type' not in payload_keys:
        raise exceptions.MissingRequiredClaimError('type')
    if 'identity' not in payload_keys:
        raise exceptions.MissingRequiredClaimError('identity')
    if 'iat' not in payload_keys:
        raise exceptions.MissingRequiredClaimError('iat')

    # signature compare
    if bsignature is not make_signature(bheader, bpayload, secret):
        raise exceptions.InvalidSignatureError('Invalid token signature')

    # expire check
    if payload['exp'] > int(time.time()):
        raise exceptions.ExpiredSignatureError('Token has been expired')

    return header, payload
github NovemberOscar / Flask-GraphQL-Auth / auge / api_auge.py View on Github external
bheader, bpayload, bsignature = token.split('.')
    header = json.loads(bheader.decode())
    payload = json.loads(bpayload.decode())

    # claim check
    payload_keys = list(payload.keys())
    if 'jti' not in payload_keys:
        raise exceptions.MissingRequiredClaimError('jti')
    if 'exp' not in payload_keys:
        raise exceptions.MissingRequiredClaimError('exp')
    if 'type' not in payload_keys:
        raise exceptions.MissingRequiredClaimError('type')
    if 'identity' not in payload_keys:
        raise exceptions.MissingRequiredClaimError('identity')
    if 'iat' not in payload_keys:
        raise exceptions.MissingRequiredClaimError('iat')

    # signature compare
    if bsignature is not make_signature(bheader, bpayload, secret):
        raise exceptions.InvalidSignatureError('Invalid token signature')

    # expire check
    if payload['exp'] > int(time.time()):
        raise exceptions.ExpiredSignatureError('Token has been expired')

    return header, payload
github yunojuno / django-request-token / request_token / utils.py View on Github external
def check_mandatory_claims(
    payload: dict, claims: Sequence[str] = MANDATORY_CLAIMS
) -> None:
    """Check dict for mandatory claims."""
    for claim in claims:
        if claim not in payload:
            raise exceptions.MissingRequiredClaimError(claim)