summaryrefslogtreecommitdiffstats
path: root/src/async/auth.rs
blob: 6f593c4e0e9e6952f037fd4a2653680578a33c4c (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
//! Authentication mechanisms for async client
use async_mutex::Mutex;
use std::cell::RefCell;

use crate::{
    entities::{account::Account, card::Card, context::Context, status::Status},
    errors::{Error, Result},
    requests::StatusesRequest,
};
use http_types::{Method, Request, Response};
use hyper_old_types::header::{parsing, Link, RelationType};
use serde::Serialize;
use smol::{prelude::*, Async};
use std::net::{TcpStream, ToSocketAddrs};
use url::Url;

/// strategies for authenticating mastodon requests need to implement this trait
#[async_trait::async_trait]
pub trait Authenticate {
    async fn authenticate(&self, request: &mut Request) -> Result<()>;
}

/// The null-strategy, will only allow the client to call public API endpoints
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Unauthenticated;
#[async_trait::async_trait]
impl Authenticate for Unauthenticated {
    async fn authenticate(&self, _: &mut Request) -> Result<()> {
        Ok(())
    }
}

/// Authenticates to the server via oauth
#[derive(Debug, Clone, PartialEq)]
pub struct OAuth {
    client_id: String,
    client_secret: String,
    redirect: String,
    token: String,
}
#[async_trait::async_trait]
impl Authenticate for Mutex<RefCell<Option<OAuth>>> {
    async fn authenticate(&self, _: &mut Request) -> Result<()> {
        unimplemented!()
    }
}