这是我在 axum 项目的 Cargo.toml 上使用的板条箱: jwt-authorizer =“0.14.0”
这是我的方法签名:
pub async fn find_balances(
Path(account_string): Path<String>,
query_params: Query<QueryParams>,
header_map: HeaderMap,
JwtClaims(user): JwtClaims<RegisteredClaims>,
State(client): State<Client>,
) -> Result<Json<SaldoDTO>, Error> {
我想访问“client_id”自定义声明。
此声明无法从
JwtClaims(user): JwtClaims<RegisteredClaims>
检索
我怎样才能得到它?
您只需要创建自己的派生类型
serde::Deserialize
。您可以使用 RegisteredClaims
让 #[serde(flatten)]
完成大部分繁重的工作。
#[derive(serde::Deserialize)]
struct Claims {
#[serde(flatten)]
pub standard: RegisteredClaims,
pub client_id: ClientId,
}
由于您没有指定
client_id
字段的类型,因此我在这里使用了占位符 ClientId
。将其替换为字段的实际类型。