diff --git a/rs/canister/CHANGELOG.md b/rs/canister/CHANGELOG.md index d10b764..27de4eb 100644 --- a/rs/canister/CHANGELOG.md +++ b/rs/canister/CHANGELOG.md @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [unreleased] +### Removed + +- Remove `http_request` endpoint ([#44](https://github.com/open-chat-labs/ic-sign-in-with-email/pull/44)) + ## [[0.10.0](https://github.com/open-chat-labs/ic-sign-in-with-email/releases/tag/v0.10.0)] - 2024-06-06 ### Changed diff --git a/rs/canister/impl/src/queries/http_request.rs b/rs/canister/impl/src/queries/http_request.rs deleted file mode 100644 index 0f85bf1..0000000 --- a/rs/canister/impl/src/queries/http_request.rs +++ /dev/null @@ -1,71 +0,0 @@ -use crate::state::AuthResult; -use crate::{env, get_query_param_value, state}; -use ic_cdk::{query, update}; -use ic_http_certification::{HttpRequest, HttpResponse}; -use magic_links::SignedMagicLink; - -#[query] -fn http_request(request: HttpRequest) -> HttpResponse { - handle_http_request(request, false) -} - -#[update] -fn http_request_update(request: HttpRequest) -> HttpResponse { - handle_http_request(request, true) -} - -fn handle_http_request(request: HttpRequest, update: bool) -> HttpResponse { - let Ok(path) = request.get_path() else { - return not_found(); - }; - - match path.as_str() { - "/auth" => { - let query = request.get_query().unwrap().unwrap_or_default(); - let params = querystring::querify(&query); - let ciphertext = get_query_param_value(¶ms, "c").unwrap(); - let encrypted_key = get_query_param_value(¶ms, "k").unwrap(); - let nonce = get_query_param_value(¶ms, "n").unwrap(); - let signature = get_query_param_value(¶ms, "s").unwrap(); - let code = get_query_param_value(¶ms, "u").unwrap(); - - let signed_magic_link = - SignedMagicLink::from_hex_strings(&ciphertext, &encrypted_key, &nonce, &signature); - - let (status_code, body, upgrade) = match state::mutate(|s| { - s.process_auth_request(signed_magic_link, code, update, env::now()) - }) { - AuthResult::Success => ( - 200, - "Successfully signed in! You may now close this tab and return to OpenChat" - .to_string(), - false, - ), - AuthResult::RequiresUpgrade => (200, "".to_string(), true), - AuthResult::LinkExpired => (400, "Link expired".to_string(), false), - AuthResult::LinkInvalid(error) => (400, format!("Link invalid: {error}"), false), - AuthResult::CodeIncorrect => (400, "Code incorrect".to_string(), false), - }; - - HttpResponse { - status_code, - headers: vec![ - ("content-type".to_string(), "text/plain".to_string()), - ("content-length".to_string(), body.len().to_string()), - ], - body: body.into_bytes(), - upgrade: upgrade.then_some(true), - } - } - _ => not_found(), - } -} - -fn not_found() -> HttpResponse { - HttpResponse { - status_code: 404, - headers: Vec::new(), - body: Vec::new(), - upgrade: None, - } -} diff --git a/rs/canister/impl/src/queries/mod.rs b/rs/canister/impl/src/queries/mod.rs index ad8c8a1..d3f4b49 100644 --- a/rs/canister/impl/src/queries/mod.rs +++ b/rs/canister/impl/src/queries/mod.rs @@ -1,4 +1,3 @@ pub mod email_sender_config; pub mod get_delegation; -pub mod http_request; pub mod rsa_public_key;