From 3f19e7d73c0664e8aa671ecd1271faf666d43bd4 Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Thu, 10 Mar 2022 12:59:26 -0800 Subject: [PATCH] Show sso errors on the last step of the oidc process --- service/OneService.cpp | 94 +++++++++++++++++++++++++----------------- zeroidc/src/lib.rs | 7 ++++ 2 files changed, 63 insertions(+), 38 deletions(-) diff --git a/service/OneService.cpp b/service/OneService.cpp index 2f9f9a0b7..8072a764b 100644 --- a/service/OneService.cpp +++ b/service/OneService.cpp @@ -147,8 +147,47 @@ size_t curlResponseWrite(void *ptr, size_t size, size_t nmemb, std::string *data } #endif + namespace ZeroTier { +const char *ssoResponseTemplate = "\ +\ +\ +\ +\ +





\ +
\ +
\ +
%s
\ +
\ +\ +"; + // Configured networks class NetworkState { @@ -1668,8 +1707,21 @@ public: } #if OIDC_SUPPORTED } else if (ps[0] == "sso") { + char resBuf[4096] = {0}; + const char *error = zeroidc::zeroidc_get_url_param_value("error", path.c_str()); + if (error != nullptr) { + const char *desc = zeroidc::zeroidc_get_url_param_value("error_description", path.c_str()); + scode = 500; + char errBuff[256] = {0}; + sprintf(errBuff, "ERROR %s: %s", error, desc); + sprintf(resBuf, ssoResponseTemplate, errBuff); + responseBody = std::string(resBuf); + responseContentType = "text/html"; + return scode; + } + // SSO redirect handling - const char* state = zeroidc::zeroidc_get_url_param_value("state", path.c_str()); + const char* state = zeroidc::zeroidc_get_url_param_value("state", path.c_str()); const char* nwid = zeroidc::zeroidc_network_id_from_state(state); const uint64_t id = Utils::hexStrToU64(nwid); @@ -1679,43 +1731,9 @@ public: const char* code = zeroidc::zeroidc_get_url_param_value("code", path.c_str()); ns.doTokenExchange(code); scode = 200; - responseBody = "\ -\ -\ -\ -\ -





\ -
\ -
\ -
Authentication Successful. You may now access the network.
\ -
\ -\ -"; + sprintf(resBuf, ssoResponseTemplate, "Authentication Successful. You may now access the network."); + responseBody = std::string(resBuf); + responseContentType = "text/html"; return scode; } else { diff --git a/zeroidc/src/lib.rs b/zeroidc/src/lib.rs index a5db2319f..80c13bb74 100644 --- a/zeroidc/src/lib.rs +++ b/zeroidc/src/lib.rs @@ -325,6 +325,13 @@ impl ZeroIDC { println!("Central post failed: {}", r.status().to_string()); println!("hit url: {}", r.url().as_str()); println!("Status: {}", r.status()); + if let Ok(body) = r.bytes() { + if let Ok(body) = std::str::from_utf8(&body) { + println!("Body: {}", body); + } + + } + (*inner_local.lock().unwrap()).exp_time = 0; (*inner_local.lock().unwrap()).running = false; }