private EIDResult cancelRequest(string endpoint, string postData) { HttpRequest httpRequest = new HttpRequest(caCertificate, clientCertificate); HttpResponse httpResponse = httpRequest.Post(httpEndpoint + "/" + endpoint, postData).Result; return(EIDResult.CreateCancelledResult()); }
public EIDResult DeleteOrgId(string id) { JObject postData = new JObject(); postData["identifier"] = id; string encodedData = "deleteOrganisationIdRequest=" + System.Convert.ToBase64String(System.Text.ASCIIEncoding.UTF8.GetBytes(postData.ToString())); HttpRequest httpRequest = new HttpRequest(caCertificate, clientCertificate); HttpResponse httpResponse = httpRequest.Post(httpEndpoint + "/organisation/management/orgId/1.0/delete", encodedData).Result; if (httpResponse.HttpStatusCode == 200) { return(EIDResult.CreateOKResult("deleted", "The org id was successfully deleted")); } if (httpResponse.ContainsKey("code")) { switch (httpResponse["code"].ToString()) { case "4000": case "4001": return(EIDResult.CreateErrorResult("request_id_invalid", "The supplied org id is not valid")); case "1008": case "1004": return(EIDResult.CreateErrorResult("cancelled_by_idp", "The IdP have cancelled the request: Permission denied")); default: return(EIDResult.CreateErrorResult("api_error", "A communications error occured", httpResponse["message"].ToString())); } } return(EIDResult.CreateErrorResult("api_error", httpResponse.HttpStatusMessage)); }
private EIDResult cancelRequest(string id) { JObject postData = new JObject(); postData["orderRef"] = id; HttpRequest httpRequest = new HttpRequest(caCertificate, clientCertificate); HttpResponse httpResponse = httpRequest.Post(httpEndpoint + "/cancel", postData).Result; return(EIDResult.CreateCancelledResult()); }
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)); } }
public override EIDResult InitSignRequest(string id, string text) { if (String.IsNullOrEmpty(text)) { return(EIDResult.CreateErrorResult("request_text_invalid", "The supplied agreement text is not valid")); } JObject postData = new JObject(); postData["personalNumber"] = id; postData["requirement"] = new JObject(); postData["requirement"]["allowFingerprint"] = allowFingerprint; postData["endUserIp"] = "127.0.0.1"; postData["userVisibleData"] = System.Convert.ToBase64String(System.Text.ASCIIEncoding.UTF8.GetBytes(text)); return(initRequest("sign", postData)); }
public override EIDResult InitSignRequest(string id, string text) { if (String.IsNullOrEmpty(text)) { return(EIDResult.CreateErrorResult("request_text_invalid", "The supplied agreement text is not valid")); } JObject postData = new JObject(); postData["minRegistrationLevel"] = minimumLevel.ToString(); postData["userInfoType"] = idType.ToString(); postData["signatureType"] = "SIMPLE"; postData["dataToSignType"] = "SIMPLE_UTF8_TEXT"; JObject dataToSign = new JObject(); dataToSign["text"] = System.Convert.ToBase64String(System.Text.ASCIIEncoding.UTF8.GetBytes(text)); postData["dataToSign"] = dataToSign; if (idType == UserInfo.SSN) { JObject userInfo = new JObject(); userInfo["country"] = defaultCountry.ToString(); userInfo["ssn"] = id; postData["userInfo"] = System.Convert.ToBase64String(System.Text.ASCIIEncoding.UTF8.GetBytes(userInfo.ToString())); } else { postData["userInfo"] = id; } JArray attributeArray = new JArray(); foreach (string attrib in attributeList.ToString().Replace(" ", "").Split(',')) { JObject wrappingObject = new JObject(); wrappingObject["attribute"] = attrib; attributeArray.Add(wrappingObject); } postData["attributesToReturn"] = attributeArray; string encodedData = "initSignRequest=" + System.Convert.ToBase64String(System.Text.ASCIIEncoding.UTF8.GetBytes(postData.ToString())); return(initRequest("sign/1.0/initSignature", encodedData)); }
public EIDResult DeleteCustomIdentifier(string customid) { JObject postData = new JObject(); postData["customIdentifier"] = customid; string encodedData = "deleteCustomIdentifierRequest=" + System.Convert.ToBase64String(System.Text.ASCIIEncoding.UTF8.GetBytes(postData.ToString())); HttpRequest httpRequest = new HttpRequest(caCertificate, clientCertificate); HttpResponse httpResponse = httpRequest.Post(httpEndpoint + "/user/manage/1.0/deleteCustomIdentifier", encodedData).Result; if (httpResponse.HttpStatusCode == 204) { return(EIDResult.CreateOKResult("deleted", "The custom ID was successfully deleted")); } if (httpResponse.ContainsKey("message")) { return(EIDResult.CreateErrorResult("api_error", httpResponse["message"].ToString())); } return(EIDResult.CreateErrorResult("api_error", httpResponse.HttpStatusMessage)); }
public EIDResult CreateCustomIdentifier(string id, string customid) { JObject postData = new JObject(); postData["userInfoType"] = idType.ToString(); postData["customIdentifier"] = customid; if (idType == UserInfo.SSN) { JObject userInfo = new JObject(); userInfo["country"] = defaultCountry.ToString(); userInfo["ssn"] = id; postData["userInfo"] = System.Convert.ToBase64String(System.Text.ASCIIEncoding.UTF8.GetBytes(userInfo.ToString())); } else { postData["userInfo"] = id; } string encodedData = "setCustomIdentifierRequest=" + System.Convert.ToBase64String(System.Text.ASCIIEncoding.UTF8.GetBytes(postData.ToString())); HttpRequest httpRequest = new HttpRequest(caCertificate, clientCertificate); HttpResponse httpResponse = httpRequest.Post(httpEndpoint + "/user/manage/1.0/setCustomIdentifier", encodedData).Result; if (httpResponse.HttpStatusCode == 204) { return(EIDResult.CreateOKResult("created", "The custom ID was successfully set")); } if (httpResponse.ContainsKey("message")) { return(EIDResult.CreateErrorResult("api_error", httpResponse["message"].ToString())); } return(EIDResult.CreateErrorResult("api_error", httpResponse.HttpStatusMessage)); }
private async Task <EIDResult> addOrgIdRequest(string id, string title, string attribute, string value, IProgress <EIDResult> progress = null, CancellationToken ct = default(CancellationToken)) { return(await Task.Run(() => { EIDResult initRequest = InitAddOrgIdRequest(id, title, attribute, value); if (initRequest.Status != EIDResult.ResultStatus.initialized) { return initRequest; } progress?.Report(initRequest); OnRequestEvent(new EIDClientEvent(initRequest)); while (true) { Thread.Sleep(2000); EIDResult pollRequest = PollAddOrgIdResult((string)initRequest["id"]); if (pollRequest.Status == EIDResult.ResultStatus.error || pollRequest.Status == EIDResult.ResultStatus.ok || pollRequest.Status == EIDResult.ResultStatus.cancelled) { return pollRequest; } progress?.Report(pollRequest); OnRequestEvent(new EIDClientEvent(pollRequest)); if (ct.IsCancellationRequested) { EIDResult cancelRequest = CancelAddOrgIdRequest((string)initRequest["id"]); progress?.Report(cancelRequest); OnRequestEvent(new EIDClientEvent(cancelRequest)); ct.ThrowIfCancellationRequested(); } } })); }
public static PSObject EIDResult(EIDResult objectToDecorate) { return(EIDResult(objectToDecorate, null, null)); }
private EIDResult pollRequest(string endpoint, string postData) { HttpRequest httpRequest = new HttpRequest(caCertificate, clientCertificate); HttpResponse httpResponse = httpRequest.Post(httpEndpoint + "/" + endpoint, postData).Result; if (httpResponse.ContainsKey("status")) { switch (httpResponse["status"].ToString()) { case "EXPIRED": return(EIDResult.CreateErrorResult("expired_transaction", "The transaction was not completed in time")); case "DELIVERED_TO_MOBILE": return(EIDResult.CreatePendingResult("pending_user_in_app", "User have started the app")); case "STARTED": return(EIDResult.CreatePendingResult("pending_delivered", "Delivered to mobile phone")); case "CANCELED": case "REJECTED": return(EIDResult.CreateErrorResult("cancelled_by_user", "The user declined transaction")); case "RP_CANCELED": return(EIDResult.CreateErrorResult("cancelled_by_idp", "The IdP have cancelled the request")); case "APPROVED": JSonWebToken jsonWebToken = JSonWebToken.FromString(httpResponse["details"].ToString(), jwtCerts); if (!jsonWebToken.IsValid) { return(EIDResult.CreateErrorResult("api_error", "JWT Token validation failed")); } if (jsonWebToken.Payload.ContainsKey("orgIdRef")) { return(EIDResult.CreateOKResult("orgid_created", "The organisational id have been issued.")); } JObject requestedAttributes = (JObject)jsonWebToken.Payload["requestedAttributes"]; //Process name string givenName = string.Empty; string surName = string.Empty; string fullName = string.Empty; if (requestedAttributes.ContainsKey("basicUserInfo")) { givenName = requestedAttributes["basicUserInfo"]["name"].ToString(); surName = requestedAttributes["basicUserInfo"]["surname"].ToString(); fullName = givenName + " " + surName; } //Process identifier string identifier = string.Empty; if (jsonWebToken.Payload["userInfoType"].ToString() == "SSN") { JObject userInfo = JsonConvert.DeserializeObject <JObject>(jsonWebToken.Payload["userInfo"].ToString()); identifier = userInfo["ssn"].ToString(); } else { identifier = jsonWebToken.Payload["userInfo"].ToString(); } //Assemble basic response JObject result = new JObject(); result["user"] = new JObject(); result["user"]["id"] = identifier; result["user"]["firstname"] = givenName; result["user"]["lastname"] = surName; result["user"]["fullname"] = fullName; result["extra"] = new JObject(); if (requestedAttributes.ContainsKey("dateOfBirth")) { result["extra"]["date_of_birth"] = requestedAttributes["dateOfBirth"].ToString(); } if (requestedAttributes.ContainsKey("emailAddress")) { result["extra"]["email_address"] = requestedAttributes["emailAddress"].ToString(); } if (requestedAttributes.ContainsKey("allEmailAddresses")) { result["extra"]["all_email_addresses"] = requestedAttributes["allEmailAddresses"].ToString(); } if (requestedAttributes.ContainsKey("addresses")) { result["extra"]["addresses"] = requestedAttributes["addresses"].ToString(); } if (requestedAttributes.ContainsKey("customIdentifier")) { result["extra"]["custom_identifier"] = requestedAttributes["customIdentifier"].ToString(); } if (requestedAttributes.ContainsKey("ssn")) { result["extra"]["ssn_number"] = requestedAttributes["ssn"]["ssn"].ToString(); result["extra"]["ssn_country"] = requestedAttributes["ssn"]["country"].ToString(); } return(EIDResult.CreateCompletedResult(result)); default: return(EIDResult.CreateErrorResult("api_error", httpResponse["hintCode"].ToString())); } } if (httpResponse.ContainsKey("code")) { switch (httpResponse["code"].ToString()) { case "1012": return(EIDResult.CreateErrorResult("cancelled_by_idp", "The IdP have cancelled the request: Not found")); case "1005": return(EIDResult.CreateErrorResult("cancelled_by_idp", "The IdP have cancelled the request: Blocked application")); case "2000": return(EIDResult.CreateErrorResult("already_in_progress", "A transaction was already pending for this SSN")); case "1002": return(EIDResult.CreateErrorResult("request_ssn_invalid", "The supplied SSN is not valid")); case "1100": return(EIDResult.CreateErrorResult("request_id_invalid", "The supplied request cannot be found")); default: return(EIDResult.CreateErrorResult("api_error", httpResponse["message"].ToString())); } } return(EIDResult.CreateErrorResult("system_error", "A communications error occured", httpResponse.HttpStatusMessage)); }
public static PSObject EIDResult(EIDResult objectToDecorate, List <PSNoteProperty> fields, List <string> defaults) { // List of properties to add and defaults to set if (fields is null) { fields = new List <PSNoteProperty>(); } if (defaults is null) { defaults = new List <string>(); } //Create the object PSObject resultObject = new PSObject(objectToDecorate); resultObject.Members.Add(new PSNoteProperty("Status", objectToDecorate.Status)); //Setup response specific display properties switch (objectToDecorate.Status) { case eidprovider.EIDResult.ResultStatus.initialized: fields.Add(new PSNoteProperty("Id", objectToDecorate["id"].ToString())); fields.Add(new PSNoteProperty("Code", "initialized")); fields.Add(new PSNoteProperty("AutostartToken", objectToDecorate["extra"]["autostart_token"].ToString())); fields.Add(new PSNoteProperty("AutostartUrl", objectToDecorate["extra"]["autostart_url"].ToString())); defaults.InsertRange(0, new string[] { "Status", "Code", "Id" }); break; case eidprovider.EIDResult.ResultStatus.error: fields.Add(new PSNoteProperty("Code", objectToDecorate["code"].ToString())); fields.Add(new PSNoteProperty("Description", objectToDecorate["description"].ToString())); fields.Add(new PSNoteProperty("Details", KeyExist(objectToDecorate, "details") ? objectToDecorate["details"].ToString() : string.Empty)); defaults.InsertRange(0, new string[] { "Status", "Code" }); break; case eidprovider.EIDResult.ResultStatus.pending: fields.Add(new PSNoteProperty("Code", objectToDecorate["code"].ToString())); fields.Add(new PSNoteProperty("Description", objectToDecorate["description"].ToString())); defaults.InsertRange(0, new string[] { "Status", "Code" }); break; case eidprovider.EIDResult.ResultStatus.ok: fields.Add(new PSNoteProperty("Code", objectToDecorate["code"].ToString())); fields.Add(new PSNoteProperty("Description", objectToDecorate["description"].ToString())); defaults.InsertRange(0, new string[] { "Status", "Code" }); PSObject okExtraObject = new PSObject(); if (KeyExist(objectToDecorate, "extra")) { ((JObject)objectToDecorate["extra"]).Properties().Select(p => p.Name).ToList().ForEach((item) => { okExtraObject.Members.Add(new PSNoteProperty(item, objectToDecorate["extra"][item].ToString())); }); } fields.Add(new PSNoteProperty("Extra", okExtraObject)); break; case eidprovider.EIDResult.ResultStatus.completed: fields.Add(new PSNoteProperty("Id", objectToDecorate["user"]["id"].ToString())); fields.Add(new PSNoteProperty("Code", "completed")); fields.Add(new PSNoteProperty("Firstname", objectToDecorate["user"]["firstname"].ToString())); fields.Add(new PSNoteProperty("Lastname", objectToDecorate["user"]["lastname"].ToString())); fields.Add(new PSNoteProperty("Fullname", objectToDecorate["user"]["fullname"].ToString())); PSObject psCustomObject = new PSObject(); if (KeyExist(objectToDecorate, "extra")) { ((JObject)objectToDecorate["extra"]).Properties().Select(p => p.Name).ToList().ForEach((item) => { psCustomObject.Members.Add(new PSNoteProperty(item, objectToDecorate["extra"][item].ToString())); }); } fields.Add(new PSNoteProperty("Extra", psCustomObject)); defaults.InsertRange(0, new string[] { "Status", "Id", "Firstname", "Lastname", "Fullname" }); break; default: defaults.InsertRange(0, new string[] { "Status" }); break; } // Add the new properties to the real object fields.ForEach((p) => { resultObject.Members.Add(p); }); //Add default display designator PSPropertySet defaltDisplayProperties = new PSPropertySet("DefaultDisplayPropertySet", defaults.ToArray()); resultObject.Members.Add(new PSMemberSet("PSStandardMembers", new[] { defaltDisplayProperties })); return(resultObject); }
public static PSObject EIDResult(EIDResult objectToDecorate, List <string> additonalDefaults) { return(EIDResult(objectToDecorate, null, additonalDefaults)); }
public static PSObject EIDResult(EIDResult objectToDecorate, List <PSNoteProperty> additionalFields) { return(EIDResult(objectToDecorate, additionalFields, null)); }
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)); } }
private EIDResult pollRequest(string id) { JObject postData = new JObject(); postData["orderRef"] = id; HttpRequest httpRequest = new HttpRequest(caCertificate, clientCertificate); HttpResponse httpResponse = httpRequest.Post(httpEndpoint + "/collect", postData).Result; if (httpResponse.ContainsKey("hintCode")) { switch (httpResponse["hintCode"].ToString()) { case "expiredTransaction": return(EIDResult.CreateErrorResult("expired_transaction", "The transaction was not completed in time")); case "outstandingTransaction": return(EIDResult.CreatePendingResult("pending_notdelivered", "The transaction has not initialized yet")); case "userSign": return(EIDResult.CreatePendingResult("pending_user_in_app", "User have started the app")); case "noClient": return(EIDResult.CreatePendingResult("pending_delivered", "Delivered to mobile phone")); case "userCancel": return(EIDResult.CreateErrorResult("cancelled_by_user", "The user declined transaction")); case "cancelled": return(EIDResult.CreateErrorResult("cancelled_by_idp", "The IdP have cancelled the request")); default: return(EIDResult.CreateErrorResult("api_error", httpResponse["hintCode"].ToString())); } } if (httpResponse.ContainsKey("completionData")) { JObject result = new JObject(); result["user"] = new JObject(); result["user"]["id"] = httpResponse["completionData"]["user"]["personalNumber"].ToString(); result["user"]["firstname"] = httpResponse["completionData"]["user"]["givenName"].ToString(); result["user"]["lastname"] = httpResponse["completionData"]["user"]["surname"].ToString(); result["user"]["fullname"] = httpResponse["completionData"]["user"]["name"].ToString(); result["extra"] = new JObject(); result["extra"]["signature"] = httpResponse["completionData"]["signature"].ToString(); result["extra"]["ocspResponse"] = httpResponse["completionData"]["ocspResponse"].ToString(); return(EIDResult.CreateCompletedResult(result)); } if (httpResponse.ContainsKey("errorCode")) { switch (httpResponse["errorCode"].ToString()) { case "invalidParameters": return(EIDResult.CreateErrorResult("request_id_invalid", "The supplied request cannot be found")); default: return(EIDResult.CreateErrorResult("api_error", httpResponse["errorCode"].ToString())); } } return(EIDResult.CreateErrorResult("system_error", "A communications error occured", httpResponse.HttpStatusMessage)); }
private static bool KeyExist(EIDResult resultObject, string keyName) { return(!String.IsNullOrEmpty(resultObject[keyName]?.ToString())); }