Beispiel #1
0
        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));
        }
Beispiel #2
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));
        }