浏览代码

Handle sso token exchange errors in zerotier client

Grant Limberg 3 年之前
父节点
当前提交
4151749dc9
共有 2 个文件被更改,包括 19 次插入4 次删除
  1. 18 3
      service/OneService.cpp
  2. 1 1
      zeroidc/src/ext.rs

+ 18 - 3
service/OneService.cpp

@@ -1729,9 +1729,24 @@ public:
 					NetworkState& ns = _nets[id];
 					char* code = zeroidc::zeroidc_get_url_param_value("code", path.c_str());
 					char *ret = ns.doTokenExchange(code);
-					scode = 200;
-					sprintf(resBuf, ssoResponseTemplate, "Authentication Successful. You may now access the network.");
-					responseBody = std::string(resBuf);
+					json ssoResult = json::parse(ret);
+					if (ssoResult.is_object()) {
+						if (ssoResult.contains("errorMessage")) {
+							std::string errorMessage = ssoResult["errorMessage"];
+							char errBuff[256] = {0};
+							sprintf(errBuff, "ERROR: %s", errorMessage.c_str());
+							sprintf(resBuf, ssoResponseTemplate, errBuff);
+							scode = 500;
+						} else {
+							scode = 200;
+							sprintf(resBuf, ssoResponseTemplate, "Authentication Successful. You may now access the network.");
+							responseBody = std::string(resBuf);
+						}
+					} else {
+						// not an object? We got a problem
+						sprintf(resBuf, ssoResponseTemplate, "Error: Unknown SSO response.");
+						scode= 500;
+					}
 
 					zeroidc::free_cstr(code);
 					zeroidc::free_cstr(ret);

+ 1 - 1
zeroidc/src/ext.rs

@@ -275,7 +275,7 @@ pub extern "C" fn zeroidc_token_exchange(idc: *mut ZeroIDC, code: *const c_char
 
         },
         Err(e) => {
-            let errstr = format!("{{\"message\":\"{}\"\"}}", e).to_string();
+            let errstr = format!("{{\"errorMessage\":\"{}\"\"}}", e).to_string();
             let ret = CString::new(errstr).unwrap();
             return ret.into_raw();
         }