From d7929e7e9fee879a28871c2195620869db291441 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 5 Sep 2022 17:57:28 +0200 Subject: feat: add authentication --- src/auth/service.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/auth/service.rs (limited to 'src/auth/service.rs') diff --git a/src/auth/service.rs b/src/auth/service.rs new file mode 100644 index 0000000..b9b44d4 --- /dev/null +++ b/src/auth/service.rs @@ -0,0 +1,40 @@ +use actix_web::web::{Data, Query}; +use actix_web::{get, HttpResponse}; +use serde::Deserialize; +use tokio::sync::mpsc; + +use crate::auth::AuthCode; + +#[derive(Debug, Deserialize)] +struct AuthCodeQuery +{ + error_reason: Option, + code: Option, +} + +#[get("/")] +async fn retrieve_auth_code( + query: Query, + done_tx: Data>, +) -> HttpResponse +{ + if let Some(error_reason) = &query.error_reason { + return HttpResponse::Unauthorized().body(format!( + "Error: No authentication code was retrieved. Reason: {}\n\nYou can close this tab", + error_reason + )); + } + + let auth_code = match &query.code { + Some(auth_code) => auth_code, + None => { + return HttpResponse::BadRequest() + .body("Error: No authentication code was retrieved"); + } + }; + + done_tx.send(auth_code.clone()).await.unwrap(); + + HttpResponse::Ok() + .body("Authentication code was successfully retrieved.\n\nYou can close this tab") +} -- cgit v1.2.3-18-g5258