Class JwtAuth
java.lang.Object
io.github.xezzon.zeroweb.auth.JwtAuth
JWT 认证工具类,用于管理和获取当前线程的 JWT 认证信息。
支持从
ScopedValue 和 gRPC Context 中获取认证数据。- Author:
- xezzon
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ScopedValue<io.github.xezzon.zeroweb.auth.JwtClaim> ScopedValue 用于在当前线程范围内存储 JWT 认证信息。static final io.grpc.Context.Key<io.github.xezzon.zeroweb.auth.JwtClaim> gRPC Context.Key 用于在 gRPC 请求上下文中存储 JWT 认证信息。 -
Method Summary
-
Field Details
-
CLAIM
ScopedValue 用于在当前线程范围内存储 JWT 认证信息。 -
CONTEXT
public static final io.grpc.Context.Key<io.github.xezzon.zeroweb.auth.JwtClaim> CONTEXTgRPC Context.Key 用于在 gRPC 请求上下文中存储 JWT 认证信息。
-
-
Method Details
-
get
获取当前线程的 JWT 认证信息。 优先从 gRPC Context 中获取,如果不存在,则从 ScopedValue 中获取。 如果两种方式都未获取到,则返回Optional.empty()。- Returns:
- 包含 JWT 认证信息的 Optional 对象,如果不存在则为 empty。
-
getOrThrow
public static @NonNull io.github.xezzon.zeroweb.auth.JwtClaim getOrThrow()获取当前线程的 JWT 认证信息,如果不存在则抛出异常。 优先从 gRPC Context 中获取,如果不存在,则从 ScopedValue 中获取。- Returns:
- JWT 认证信息。
- Throws:
cn.dev33.satoken.exception.NotLoginException- 如果当前线程没有认证信息。
-