Skip to main content

AuthProvider

Trait AuthProvider 

Source
pub trait AuthProvider:
    Debug
    + Send
    + Sync {
    // Required methods
    fn login<'life0, 'life1, 'async_trait>(
        &'life0 self,
        token: Option<&'life1 str>,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn logout<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn status<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<AuthStatus>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn token<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

认证操作的平台抽象。

所有平台实现(GitHub/GitLab/GitCode)都必须实现此 trait, 以提供统一的登录、登出、状态查询及 Token 获取能力。

§Errors

所有方法在平台调用失败、反序列化失败或鉴权失败时返回 CoreError。

Required Methods§

Source

fn login<'life0, 'life1, 'async_trait>( &'life0 self, token: Option<&'life1 str>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

执行登录流程(交互式或非交互式)。

如果提供了 token,则使用 token 进行非交互式登录; 否则启动交互式登录流程。

登录成功后凭据会被持久化到本地存储。

§Errors

当认证失败或凭据存储失败时返回错误。

Source

fn logout<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

执行登出流程,清除本地凭据。

§Errors

当凭据清除失败时返回错误。

Source

fn status<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<AuthStatus>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

查询当前认证状态。

§Errors

当无法读取本地凭据或平台 API 调用失败时返回错误。

Source

fn token<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

获取当前有效的访问 Token。

返回的字符串可用于后续的平台 API 调用。

§Errors

当用户未登录或 Token 获取失败时返回错误。

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§