5个版本 (稳定)

使用旧的Rust 2015

4091.0.0 2022年5月16日
4084.0.0 2022年5月16日
1.0.1 2021年8月15日
1.0.0 2019年2月13日
0.1.0 2018年9月4日

身份验证中排名第193

Download history · Rust 包仓库 3106/week @ 2024-03-14 · Rust 包仓库 3964/week @ 2024-03-21 · Rust 包仓库 2880/week @ 2024-03-28 · Rust 包仓库 3484/week @ 2024-04-04 · Rust 包仓库 2204/week @ 2024-04-11 · Rust 包仓库 2082/week @ 2024-04-18 · Rust 包仓库 2431/week @ 2024-04-25 · Rust 包仓库 2700/week @ 2024-05-02 · Rust 包仓库 2298/week @ 2024-05-09 · Rust 包仓库 2994/week @ 2024-05-16 · Rust 包仓库 2096/week @ 2024-05-23 · Rust 包仓库 2220/week @ 2024-05-30 · Rust 包仓库 1959/week @ 2024-06-06 · Rust 包仓库 2705/week @ 2024-06-13 · Rust 包仓库 2620/week @ 2024-06-20 · Rust 包仓库 1906/week @ 2024-06-27 · Rust 包仓库

每月下载量9,602
8个crate中使用(7个直接使用)

GPL-3.0-or-later

29KB
292

alcoholic_jwt

这是一个使用JWKS中的密钥进行JWT验证的库,仅此而已。

RS256是JWT中最常用的非对称签名机制,例如在Google或Aprila的API中。

库的名称来源于尝试使用其他为类似目的制作的Rust库可能产生的潜在副作用。

使用概述

您从某个使用RS256签名并提供公钥的JWKS格式的身份验证提供者处检索JWT。

以下是一个在kid声明中提供用于签名的密钥ID的令牌的示例

extern crate alcoholic_jwt;

use alcoholic_jwt::{JWKS, Validation, validate, token_kid};

// The function implied here would usually perform an HTTP-GET
// on the JWKS-URL for an authentication provider and deserialize
// the result into the `alcoholic_jwt::JWKS`-struct.
let jwks: JWKS = jwks_fetching_function();

let token: String = some_token_fetching_function();

// Several types of built-in validations are provided:
let validations = vec![
  Validation::Issuer("auth.test.aprila.no".into()),
  Validation::SubjectPresent,
];

// If a JWKS contains multiple keys, the correct KID first
// needs to be fetched from the token headers.
let kid = token_kid(&token)
    .expect("Failed to decode token headers")
    .expect("No 'kid' claim present in token");

let jwk = jwks.find(&kid).expect("Specified key not found in set");

validate(token, jwk, validations).expect("Token validation has failed!");

内部机制

这个库旨在仅使用可信的现成组件来完成工作。加密操作由openssl crate提供,JSON序列化由serde_json提供。

贡献

此项目在TVL单一代码库中开发。要工作于此,您可以使用整个存储库的本地克隆,或仅克隆alcoholic_jwt子树。

https://code.tvl.fyi/depot.git:/net/alcoholic_jwt.git

请遵循TVL贡献指南

依赖项

~2.4–3.5MB
~78K SLoC