JWT API¶
文档的这一部分涵盖了 joserfc.jwt
的所有接口。
- class joserfc.jwt.ClaimsOption¶
- class joserfc.jwt.ClaimsRegistry(**kwargs: ClaimsOption)¶
Requesting "claims" for JWT with the given conditions.
- class joserfc.jwt.JWTClaimsRegistry(now: int | None = None, leeway: int = 0, **kwargs: ClaimsOption)¶
- validate_exp(value: int) None ¶
“exp”(到期时间)声明标识 JWT 必须在或之后的到期时间。处理“exp”声明要求当前日期/时间必须早于“exp”声明中列出的到期日期/时间。实现者可以提供一些小的余地,通常不超过几分钟,以考虑时钟偏差。其值必须是包含 NumericDate 值的数字。使用此声明是可选的。
- validate_iat(value: int) None ¶
“iat”(签发时间)声明标识 JWT 的签发时间。此声明可用于确定 JWT 的年龄。其值必须是包含 NumericDate 值的数字。使用此声明是可选的。
- validate_nbf(value: int) None ¶
“nbf”(不早于)声明标识 JWT 必须在之前的时间。处理“nbf”声明要求当前日期/时间必须晚于或等于“nbf”声明中列出的不早于日期/时间。实现者可以提供一些小的余地,通常不超过几分钟,以考虑时钟偏差。其值必须是包含 NumericDate 值的数字。使用此声明是可选的。
- class joserfc.jwt.Token(header: dict[str, Any], claims: dict[str, Any])¶
提取的 Token 对象,包含
header
和claims
。- 参数:
header -- JWT 的 header 部分
claims -- JWT 的有效载荷 (payload) 部分
- claims¶
字典形式的有效载荷 (payload) 声明 (claims)
- header¶
字典形式的 header
- joserfc.jwt.check_sensitive_data(claims: dict[str, Any]) None ¶
检查声明是否包含敏感信息。
- joserfc.jwt.decode(value: bytes | str, key: OctKey | RSAKey | ECKey | OKPKey | KeySet | Callable[[GuestProtocol], OctKey | RSAKey | ECKey | OKPKey | KeySet], algorithms: list[str] | None = None, registry: JWSRegistry | JWERegistry | None = None, decoder_cls: Type[JSONDecoder] | None = None) Token ¶
使用给定的密钥解码 JSON Web Token 字符串,并使用声明请求进行验证。
- 参数:
value -- JWT 的文本
key -- 用于验证签名的密钥
algorithms -- 允许的算法列表
registry -- 要使用的
JWSRegistry
或JWERegistry
decoder_cls -- A JSONDecoder subclass to use
- 触发:
BadSignatureError
- joserfc.jwt.encode(header: dict[str, Any], claims: dict[str, Any], key: OctKey | RSAKey | ECKey | OKPKey | KeySet | Callable[[GuestProtocol], OctKey | RSAKey | ECKey | OKPKey | KeySet], algorithms: list[str] | None = None, registry: JWSRegistry | JWERegistry | None = None, encoder_cls: Type[JSONEncoder] | None = None) str ¶
使用给定的 header 和声明 (claims) 编码 JSON Web Token。
- 参数:
header -- 字典形式的 JWT header 部分
claims -- 用来编码的字典形式的 JWT claims 部分
key -- 用于签名的密钥
algorithms -- 允许的算法列表
registry -- 要使用的
JWSRegistry
或JWERegistry
encoder_cls -- A JSONEncoder subclass to use