private EIDResult initRequest(string endpoint, JObject postData) { // Make the request HttpRequest httpRequest = new HttpRequest(caCertificate, clientCertificate); HttpResponse httpResponse = httpRequest.Post(httpEndpoint + "/" + endpoint, postData).Result; JObject result = new JObject(); if (httpResponse.HttpStatusCode == 200) { if (httpResponse.ContainsKey("orderRef")) { result["id"] = httpResponse["orderRef"].ToString(); result["extra"] = new JObject(); result["extra"]["autostart_token"] = httpResponse["autoStartToken"].ToString(); result["extra"]["autostart_url"] = "bankid:///?autostarttoken=" + result["extra"]["autostart_token"] + "&redirect=null"; return(EIDResult.CreateInitializedResult(result)); } return(EIDResult.CreateErrorResult("api_error", "A communications error occured")); } else { if (httpResponse.ContainsKey("errorCode")) { switch (httpResponse["errorCode"].ToString()) { case "alreadyInProgress": return(EIDResult.CreateErrorResult("already_in_progress", "A transaction was already pending for this SSN")); case "invalidParameters": switch (httpResponse["details"].ToString()) { case "Incorrect personalNumber": return(EIDResult.CreateErrorResult("request_ssn_invalid", "The supplied SSN is not valid")); case "Invalid userVisibleData": return(EIDResult.CreateErrorResult("request_text_invalid", "The supplied agreement text is not valid")); default: return(EIDResult.CreateErrorResult("api_error", "A communications error occured", httpResponse["details"].ToString())); } default: return(EIDResult.CreateErrorResult("api_error", "A communications error occured", httpResponse["errorCode"].ToString())); } } return(EIDResult.CreateErrorResult("system_error", "A communications error occured", httpResponse.HttpStatusMessage)); } }
private EIDResult initRequest(string endpoint, string postData) { // Make the request HttpRequest httpRequest = new HttpRequest(caCertificate, clientCertificate); HttpResponse httpResponse = httpRequest.Post(httpEndpoint + "/" + endpoint, postData).Result; JObject result = new JObject(); if (httpResponse.HttpStatusCode == 200) { if (httpResponse.ContainsKey("authRef") || httpResponse.ContainsKey("signRef") || httpResponse.ContainsKey("orgIdRef")) { string refCode = string.Empty; if (httpResponse.ContainsKey("authRef")) { refCode = (string)httpResponse["authRef"]; } if (httpResponse.ContainsKey("signRef")) { refCode = (string)httpResponse["signRef"]; } if (httpResponse.ContainsKey("orgIdRef")) { refCode = (string)httpResponse["orgIdRef"]; } result["id"] = refCode; result["extra"] = new JObject(); result["extra"]["autostart_token"] = refCode.ToString(); result["extra"]["autostart_url"] = "frejaeid://bindUserToTransaction?transactionReference=" + result["extra"]["autostart_token"]; return(EIDResult.CreateInitializedResult(result)); } return(EIDResult.CreateErrorResult("api_error", "A communications error occured")); } else { if (httpResponse.ContainsKey("code")) { switch (httpResponse["code"].ToString()) { case "2000": return(EIDResult.CreateErrorResult("already_in_progress", "A transaction was already pending for this SSN")); case "1001": case "1002": return(EIDResult.CreateErrorResult("request_ssn_invalid", "The supplied SSN is not valid")); case "1005": return(EIDResult.CreateErrorResult("cancelled_by_idp", "The IdP have cancelled the request: Blocked application")); case "1004": return(EIDResult.CreateErrorResult("cancelled_by_idp", "The IdP have cancelled the request: Permission denied")); case "1012": return(EIDResult.CreateErrorResult("cancelled_by_idp", "The IdP have cancelled the request: Not found")); default: return(EIDResult.CreateErrorResult("api_error", "A communications error occured", httpResponse["message"].ToString())); } } return(EIDResult.CreateErrorResult("system_error", "A communications error occured", httpResponse.HttpStatusMessage)); } }