diff options
Diffstat (limited to 'src/api/oauth.rs')
| -rw-r--r-- | src/api/oauth.rs | 60 |
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) } |
