Handle sso token exchange errors in zerotier client

This commit is contained in:
Grant Limberg 2022-05-11 19:59:58 -07:00
parent aee9521c91
commit 4151749dc9
No known key found for this signature in database
GPG Key ID: 8F2F97D3BE8D7735
2 changed files with 19 additions and 4 deletions

View File

@ -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);

View File

@ -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();
}