summaryrefslogtreecommitdiff
path: root/src/api/oauth.rs
diff options
context:
space:
mode:
authormrw1593 <botahamec@outlook.com>2023-05-29 15:56:27 -0400
committermrw1593 <botahamec@outlook.com>2023-05-29 15:56:27 -0400
commit436511846130ae5d8a058e031d9c8ad0bcb002aa (patch)
tree1ae1e35390e7555f45c2db8a011cfde38295d71f /src/api/oauth.rs
parenta84c964b725ad2012cdf6a605ff264c60e0b0e59 (diff)
Create stubbed endpoints for authorization
Diffstat (limited to 'src/api/oauth.rs')
-rw-r--r--src/api/oauth.rs60
1 files changed, 48 insertions, 12 deletions
diff --git a/src/api/oauth.rs b/src/api/oauth.rs
index 9e0e5c6..9916053 100644
--- a/src/api/oauth.rs
+++ b/src/api/oauth.rs
@@ -1,24 +1,60 @@
-use std::collections::HashMap;
+use std::str::FromStr;
-use actix_web::{web, HttpResponse};
-use serde::Deserialize;
+use actix_web::{get, post, web, HttpResponse, Scope};
+use serde::{Deserialize, Serialize};
+use sqlx::MySqlPool;
+use tera::Tera;
+use unic_langid::subtags::Language;
use url::Url;
-use uuid::Uuid;
-#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
+use crate::resources::{languages, templates};
+use crate::services::db;
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
enum ResponseType {
Code,
Token,
}
-#[derive(Debug, Clone, Deserialize)]
-struct AuthorizationParameters {
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub struct AuthorizationParameters {
response_type: ResponseType,
- client_id: Uuid,
- redirect_uri: Url,
- state: Box<str>,
+ redirect_uri: Option<Url>,
+}
+
+#[derive(Debug, Clone, Deserialize)]
+struct AuthorizeCredentials {
+ username: Box<str>,
+ password: Box<str>,
+}
+
+#[post("/authorize")]
+async fn authorize(
+ query: web::Query<AuthorizationParameters>,
+ credentials: web::Form<AuthorizeCredentials>,
+) -> HttpResponse {
+ // TODO check that the URI is valid
+ todo!()
+}
+
+#[get("/authorize")]
+async fn authorize_page(
+ db: web::Data<MySqlPool>,
+ tera: web::Data<Tera>,
+ translations: web::Data<languages::Translations>,
+ query: web::Query<AuthorizationParameters>,
+) -> HttpResponse {
+ // TODO find a better way of doing languages
+ // TODO check that the URI is valid
+ let language = Language::from_str("en").unwrap();
+ let page =
+ templates::login_page(&tera, &query, language, translations.get_ref().clone()).unwrap();
+ HttpResponse::Ok().content_type("text/html").body(page)
+}
- #[serde(flatten)]
- additional_parameters: HashMap<Box<str>, Box<str>>,
+pub fn service() -> Scope {
+ web::scope("/oauth")
+ .service(authorize_page)
+ .service(authorize)
}