openlark_auth/lib.rs
1//! # OpenLark 认证模块
2//!
3//! OpenLark SDK的认证和授权模块,提供飞书开放平台的完整认证解决方案。
4//!
5//! ## 功能特性
6//!
7//! - **令牌管理**: 自动处理访问令牌的获取、刷新和缓存
8//! - **多种认证方式**: 支持企业自建应用、应用商店应用和用户认证
9//! - **OAuth支持**: 完整的OAuth 2.0授权流程
10//! - **类型安全**: 基于Rust类型系统的API设计
11//! - **错误处理**: 统一的错误处理和用户友好的错误消息
12//! - **异步支持**: 基于tokio的全异步API设计
13//!
14//! ## 模块组织
15//!
16//! - [`services`][]: 核心认证服务
17//! - [`models`][]: 数据模型定义
18//! - `auth`: 认证 API (包含 auth, authen, oauth 子模块)
19//!
20//! ## 快速开始
21//!
22//! ```rust,no_run
23//! use openlark_auth::{AuthService, AuthenService, OAuthService};
24//! use openlark_core::config::Config;
25//!
26//! let config = Config::builder()
27//! .app_id("your_app_id")
28//! .app_secret("your_app_secret")
29//! .base_url("https://open.feishu.cn")
30//! .build();
31//!
32//! // 企业自建应用认证(这里只演示构建请求,不发送网络请求)
33//! let auth_service = AuthService::new(config.clone());
34//! let _token_builder = auth_service
35//! .v3()
36//! .app_access_token_internal()
37//! .app_id("your_app_id")
38//! .app_secret("your_app_secret");
39//!
40//! // 用户认证(这里只演示构建请求,不发送网络请求)
41//! let authen_service = AuthenService::new(config.clone());
42//! let _user_info_builder = authen_service
43//! .v1()
44//! .user_info()
45//! .get()
46//! .user_access_token("user_token");
47//!
48//! // OAuth(构建授权链接)
49//! let oauth_service = OAuthService::new(config);
50//! let _auth_url = oauth_service
51//! .old()
52//! .authorization()
53//! .app_id("your_app_id")
54//! .redirect_uri("https://example.com/callback")
55//! .build_url();
56//! ```
57
58pub mod auth;
59pub mod common;
60pub mod human_authentication;
61pub mod models;
62pub mod passport;
63pub mod services;
64pub mod token_provider;
65pub mod verification;
66pub mod verification_information;
67
68// 重新导出核心类型,方便用户使用
69pub use services::{AuthService, AuthenService, OAuthService};
70pub use token_provider::AuthTokenProvider;
71
72/// 认证模块的预导入,包含最常用的类型和特征
73pub mod prelude {
74 pub use crate::{AuthService, AuthTokenProvider, AuthenService, OAuthService};
75 pub use openlark_core::{config::Config, error::SDKResult, http::Transport};
76}
77
78/// 认证模块版本信息
79pub const VERSION: &str = env!("CARGO_PKG_VERSION");
80
81#[cfg(test)]
82#[allow(unused_imports)]
83mod tests {
84 use super::*;
85 use std::marker::PhantomData;
86
87 #[test]
88 fn test_version() {
89 assert_ne!(VERSION, "");
90 }
91
92 #[test]
93 fn test_prelude_imports() {
94 // 确保prelude中的类型可以正常导入,避免unused import警告
95 use crate::prelude::{AuthService, AuthenService, OAuthService, SDKResult};
96
97 // 这里只是验证类型导入,不进行实际操作
98 let _: String = VERSION.to_string();
99
100 // 验证导入的类型存在
101 let _ = PhantomData::<AuthService>;
102 let _ = PhantomData::<AuthenService>;
103 let _ = PhantomData::<OAuthService>;
104 let _: PhantomData<SDKResult<()>>;
105 }
106}