1use async_trait::async_trait;
2use reqwest::header::HeaderMap;
3
4use crate::error::Result;
5
6#[async_trait]
7pub trait AuthStrategy: Send + Sync {
8 async fn apply(&self, headers: &mut HeaderMap) -> Result<()>;
9}
10
11#[derive(Debug, Clone)]
13pub struct BotTokenAuth {
14 token: String,
15}
16
17impl BotTokenAuth {
18 pub fn new(token: impl Into<String>) -> Self {
19 Self {
20 token: token.into(),
21 }
22 }
23}
24
25#[async_trait]
26impl AuthStrategy for BotTokenAuth {
27 async fn apply(&self, headers: &mut HeaderMap) -> Result<()> {
28 headers.insert(
29 "Authorization",
30 format!("Bearer {}", self.token).parse().unwrap(),
31 );
32 Ok(())
33 }
34}