//-------------------------------------------------------------------------------------------------------------------- public Tuple <NodeKey, SecureString> pairGetKeys() { if (pairingState != PairingStates.TokensSentToNode) { return(null); } var req = new PairingNodeGetKeysRequest(this.token1, this.token2); var resp = (PairingServerKeysResponse)jsonPost(this.pairingPostUrl + "/" + NodePairingConstants.s_GetKeysRequest, req, typeof(PairingServerKeysResponse)); if (resp != null) { this.nodeKey = resp.nodeKey; if (this.nodeKey != null && !string.IsNullOrWhiteSpace(resp.secretKey)) { this.secretKey = resp.secretKey.ToSecureString(); onPaired(this.nodeKey.Value, this.secretKey); return(new Tuple <NodeKey, SecureString>(this.nodeKey.Value, this.secretKey)); } else { onPairingFailed("NodeKey or SecretKey are invalid"); } } else { onPairingFailed("Could not get keys"); } return(null); }
//-------------------------------------------------------------------------------------------------------------------- public Tuple <NodeKey, SecureString, HttpStatusCode> pairGetKeys() { if (pairingState != PairingStates.TokensSentToNode) { return(null); } try { var req = new PairingNodeGetKeysRequest(this.token1, this.token2); var response = Yodiwo.Tools.Http.RequestPost(this.pairingPostUrl + "/" + NodePairingConstants.s_GetKeysRequest, req.ToJSON(), HttpRequestDataFormat.Json, null); if (response.StatusCode != HttpStatusCode.OK) { onPairingFailed("HTTP Request for keys failed with " + response.StatusCode); return(new Tuple <NodeKey, SecureString, HttpStatusCode>(null, null, response.StatusCode)); } if (string.IsNullOrWhiteSpace(response.ResponseBodyText)) { onPairingFailed("HTTP Request keys returned empty body"); return(new Tuple <NodeKey, SecureString, HttpStatusCode>(null, null, response.StatusCode)); } var resp = response.ResponseBodyText.FromJSON <PairingServerKeysResponse>(); this.nodeKey = resp.nodeKey; if (this.nodeKey != null && !string.IsNullOrWhiteSpace(resp.secretKey)) { this.secretKey = resp.secretKey.ToSecureString(); onPaired(this.nodeKey.Value, this.secretKey); return(new Tuple <NodeKey, SecureString, HttpStatusCode>(this.nodeKey.Value, this.secretKey, response.StatusCode)); } else { onPairingFailed("NodeKey or SecretKey are invalid"); } } catch (Exception ex) { DebugEx.TraceErrorException(ex); } return(null); }