summaryrefslogtreecommitdiffstats
path: root/src/async/auth.rs
diff options
context:
space:
mode:
authorPaul Woolcock <paul@woolcock.us>2020-10-07 05:47:39 -0400
committerPaul Woolcock <paul@woolcock.us>2020-10-07 09:06:13 -0400
commit02ca0a89515413ac9fb3b655de2f21f6a711e0f2 (patch)
tree004bcd9f88eca168e10e1ac85c5987fdd6769fcf /src/async/auth.rs
parent04b5b54212629f058bdab1ba55c89a3d417e0454 (diff)
Add basic async client
This adds a module, accessible by compiling with `--features async`, that provides an `elefren::async::Client`. The client is runtime-agnostic, and currently only provides unauthenticated access, see the docs for the full list of methods that can be performed* with this client. * note that some API calls are publicly available by default, but can be changed via instance settings to not be publicly accessible
Diffstat (limited to 'src/async/auth.rs')
-rw-r--r--src/async/auth.rs46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/async/auth.rs b/src/async/auth.rs
new file mode 100644
index 0000000..6f593c4
--- /dev/null
+++ b/src/async/auth.rs
@@ -0,0 +1,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!()
+ }
+}