aboutsummaryrefslogtreecommitdiffstats
path: root/crates/api-auth/src/discord/mod.rs
blob: dbcb139c1195ac34828303811de3acb29a16bffe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use api_core::models::user::User;
use async_session::Session;
use async_trait::async_trait;
use oauth2::{CsrfToken, Scope};
use sh_util::cache::RedisManager;
use sqlx::PgPool;

use crate::{BasicClient, CSRF_TOKEN, OauthDriver, error::AuthError};

#[derive(Clone)]
pub struct AuthServiceDiscord {
    database: PgPool,
    cache: RedisManager,
    client: BasicClient,
}

impl AuthServiceDiscord {
    pub fn new(database: PgPool, client: BasicClient, cache: RedisManager) -> Self {
        Self {
            database,
            client,
            cache,
        }
    }
}

#[async_trait]
impl OauthDriver for AuthServiceDiscord {
    async fn get_auth_token(&self) -> Result<String, AuthError> {
        todo!()
    }
    async fn get_user(&self) -> Result<User, AuthError> {
        todo!()
    }
    async fn create_oauth_session(&self) -> Result<String, AuthError> {
        let (auth_url, csrf_token) = self
            .client
            .authorize_url(CsrfToken::new_random)
            .add_scope(Scope::new("identify".to_string()))
            .url();

        let mut session = Session::new();
        session.insert(CSRF_TOKEN, &csrf_token).unwrap();

        Ok(String::default())
    }
    async fn save_session(&self, user: &User) -> Result<(), AuthError> {
        todo!()
    }
}