Example #1
0
        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));
        }
Example #2
0
        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));
        }
Example #3
0
        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));
        }
Example #4
0
        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));
        }