7个版本 (3个稳定版本)
| 1.0.2 | 2024年4月5日 | 
|---|---|
| 1.0.1 | 2023年4月29日 | 
| 0.3.0-alpha | 2023年4月29日 | 
| 0.2.1-alpha | 2023年4月29日 | 
| 0.1.0-alpha | 2023年4月28日 | 
145 在 认证 中排名
每月418 次下载
23KB
280 行
轻量级OpenID
轻量级OpenID原语和客户端。此包可以将应用程序转换为OpenID依赖方。
警告! 此crate尚未经过审计,使用风险自负!
实现与
OpenIDConfig辅助结构交互的路由(开始和完成认证)是您的责任。此外,仅支持OpenID规范的一小部分
code授权流程- 作用域
openid profile email是硬编码的,无法更改- 使用
userinfo端点检索用户信息
基本用法
let config = OpenIDConfig::load_from_url(&AppConfig::get().configuration_url).await.unwrap();
// Start authentication
let auth_url = config.gen_authorization_url("client_id", "state", "redirect_uri");
redirect_user(auth_url);
// Finish authentication
let token_response = config.request_token("client_id", "client_secret", "code", "redirect_uri").await.unwrap();
let user_info = config.request_user_info(&token_response).await.unwrap();
// user_info now contains profile info of user
功能 crypto-wrapper
CryptoWrapper 是一个辅助工具,可以将数据加密为base64编码的字符串结构
#[derive(Encode, Decode, Eq, PartialEq, Debug)]
struct Message(String);
fun test() {
    let wrapper = CryptoWrapper::new_random();
    let msg = Message("Hello world".to_string());
    let enc = wrapper.encrypt(&msg).unwrap();
    let dec: Message = wrapper.decrypt( & enc).unwrap();
    
    assert_eq!(dec, msg);
}
注意:为了在自己的项目中使用
CryptoWrapper,您必须将bincode(版本 >= 2.0.0)作为您的依赖项之一添加。如果您决定使用BasicStateManager,则无需此依赖项。
BasicStateManager 是一个辅助工具,它使用 CryptoWrapper 生成和验证OpenID认证的状态
let ip = IpAddr::V4(Ipv4Addr::new(192, 168, 1, 1));
let manager = BasicStateManager::new();
let state = manager.gen_state(ip).unwrap();
assert!(manager.validate_state(ip, &state).is_ok());
完整示例
此crate的完整示例用法可在以下位置找到: https://gitea.communiquons.org/pierre/oidc-test-client
依赖项
~4–15MB
~214K SLoC