summaryrefslogtreecommitdiff
path: root/src/auth/service.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/auth/service.rs')
-rw-r--r--src/auth/service.rs40
1 files changed, 40 insertions, 0 deletions
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<String>,
+ code: Option<AuthCode>,
+}
+
+#[get("/")]
+async fn retrieve_auth_code(
+ query: Query<AuthCodeQuery>,
+ done_tx: Data<mpsc::Sender<AuthCode>>,
+) -> 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")
+}