blob: b9b44d4e462b0827a3c5b790a9e090441267b9e9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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")
}
|