pub struct OAuth2Server { /* private fields */ }Expand description
OAuth2 授权服务器:管理授权码的签发、验证与交换。
内部使用 Mutex<HashMap> 存储授权码,支持:
- 创建授权码(
create_authorization_code) - 用授权码交换令牌(
exchange_code) - 验证客户端凭据
- 授权码一次性消费
Implementations§
Source§impl OAuth2Server
impl OAuth2Server
Sourcepub fn register_client(
&mut self,
client_id: impl Into<String>,
client_secret: impl Into<String>,
)
pub fn register_client( &mut self, client_id: impl Into<String>, client_secret: impl Into<String>, )
注册客户端
Sourcepub fn validate_client(&self, client_id: &str, client_secret: &str) -> bool
pub fn validate_client(&self, client_id: &str, client_secret: &str) -> bool
验证客户端凭据
Sourcepub fn has_client(&self, client_id: &str) -> bool
pub fn has_client(&self, client_id: &str) -> bool
是否已注册客户端
签发授权码
验证授权请求中的 client_id 已注册后,创建一次性授权码。
Sourcepub fn exchange_code(
&self,
req: &TokenRequest,
) -> Result<AuthorizationCode, AuthError>
pub fn exchange_code( &self, req: &TokenRequest, ) -> Result<AuthorizationCode, AuthError>
用授权码交换访问令牌
验证流程:
- 授权码存在
- 授权码未过期
- 授权码未使用(一次性消费)
- redirect_uri 与签发时一致
- client_id 与签发时一致
Sourcepub fn code_count(&self) -> usize
pub fn code_count(&self) -> usize
返回当前存储的授权码数量
Auto Trait Implementations§
impl !Freeze for OAuth2Server
impl RefUnwindSafe for OAuth2Server
impl Send for OAuth2Server
impl Sync for OAuth2Server
impl Unpin for OAuth2Server
impl UnsafeUnpin for OAuth2Server
impl UnwindSafe for OAuth2Server
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more