def validate(self, token): if not self._key: raise ERROR_AUTHENTICATE_FAILURE(message='Decode key is not set.') if not isinstance(token, (str, bytes)): raise ERROR_AUTHENTICATE_FAILURE(message='Invalid token format.') try: payload = JWTUtil.decode(token, self._key) except Exception: raise ERROR_AUTHENTICATE_FAILURE(message='UnKnown Exception.') return payload
def validate(self, token, options=None): if not self._key: raise ERROR_AUTHENTICATE_FAILURE(message='Decode key is not set.') if not isinstance(token, (str, bytes)): raise ERROR_AUTHENTICATE_FAILURE(message='Invalid token format.') if options is None: options = {} try: payload = JWTUtil.decode(token, self._key, options=options) except Exception: raise ERROR_AUTHENTICATE_FAILURE( message='Token is invalid or expired.') return payload
def test_decode_jwt(self): self.test_encode_jwt() decoded = JWTUtil.decode(self.encoded, self.pub_jwk) print(f'decoded: {decoded}') self.assertDictEqual(self.payload, decoded)