예제 #1
0
        private SdkHttpClient GetClient()
        {
            SdkHttpClient client = GetSdkClient(apiUrl);

            client.DefaultRequestHeaders.Add("X-Request-ID", Guid.NewGuid().ToString());
            return(client);
        }
예제 #2
0
        public override Credentials ProcessAuthParams(SdkHttpClient client, string regionId)
        {
            if (ProjectId != null)
            {
                return(this);
            }

            var akWithName = Ak + regionId;
            var projectId  = AuthCache.GetAuth(akWithName);

            if (!string.IsNullOrEmpty(projectId))
            {
                ProjectId = projectId;
                return(this);
            }

            IamEndpoint = IsNullOrEmpty(IamEndpoint) ? IamService.DefaultIamEndpoint : IamEndpoint;
            var request = IamService.GetKeystoneListProjectsRequest(IamEndpoint, regionId);

            request = SignAuthRequest(request).Result;
            try
            {
                ProjectId = IamService.KeystoneListProjects(client, request);
                AuthCache.PutAuth(akWithName, ProjectId);
                return(this);
            }
            catch (ServiceResponseException e)
            {
                throw new ArgumentException("Failed to get project id, " + e.ErrorMsg);
            }
        }
예제 #3
0
        public static string KeystoneListAuthDomains(SdkHttpClient client, HttpRequest request)
        {
            var message = client.InitHttpRequest(request, true);

            try
            {
                var response = client.DoHttpRequest(message).Result;
                if ((int)response.StatusCode >= 400)
                {
                    throw ExceptionUtils.GetException(response);
                }

                var data = JsonUtils.DeSerialize <KeystoneListAuthDomainsResponse>(response);
                if (data?.Domains != null && data.Domains.Count > 0)
                {
                    return(data.Domains[0].Id);
                }

                throw new ArgumentException("Failed to get domain id.");
            }
            catch (AggregateException aggregateException)
            {
                throw new ConnectionException(aggregateException.Message);
            }
        }
예제 #4
0
        public static string KeystoneListProjects(SdkHttpClient client, HttpRequest request)
        {
            var message = client.InitHttpRequest(request, true);

            try
            {
                var response = client.DoHttpRequest(message).Result;
                if ((int)response.StatusCode >= 400)
                {
                    throw ExceptionUtils.GetException(response);
                }

                var data = JsonUtils.DeSerialize <KeystoneListProjectsResponse>(response);
                // TODO support create new project id here
                if (data?.Projects == null || data.Projects?.Count == 0)
                {
                    throw new ArgumentException("Failed to get project id.");
                }

                if (data.Projects.Count == 1)
                {
                    return(data.Projects[0].Id);
                }

                throw new ArgumentException(
                          "Multiple project ids have been returned, please specify one when initializing credentials.");
            }
            catch (AggregateException aggregateException)
            {
                throw new ConnectionException(aggregateException.Message);
            }
        }
        public override Credentials ProcessAuthParams(SdkHttpClient client, string regionId)
        {
            if (DomainId != null)
            {
                return(this);
            }

            var domainId = AuthCache.GetAuth(Ak);

            if (!string.IsNullOrEmpty(domainId))
            {
                DomainId = domainId;
                return(this);
            }

            IamEndpoint = IsNullOrEmpty(IamEndpoint) ? IamService.DefaultIamEndpoint : IamEndpoint;
            var request = IamService.GetKeystoneListAuthDomainsRequest(IamEndpoint);

            request = SignAuthRequest(request).Result;
            try
            {
                DomainId = IamService.KeystoneListAuthDomains(client, request);
                AuthCache.PutAuth(Ak, DomainId);
                return(this);
            }
            catch (ServiceResponseException e)
            {
                throw new ArgumentException("Failed to get domain id, " + e.ErrorMsg);
            }
        }
예제 #6
0
        private SdkHttpClient GetClient()
        {
            SdkHttpClient sdkHttpClient = GetSdkClient(apiUrl);

            sdkHttpClient.DefaultRequestHeaders.Add("Request-ID", Guid.NewGuid().ToString());
            sdkHttpClient.DefaultRequestHeaders.Add("Client-ID", _settings.AppClientId);

            return(sdkHttpClient);
        }
        internal static void SignRequest(this SdkHttpClient client, X509Certificate2 cert, HttpMethod method, string path, string headerName, string keyId, bool addSig = false)
        {
            var signingString = $"(request-target): {method.Method.ToLower()} {path}\ndate: {client.DefaultRequestHeaders.GetValues("Date").First()}\ndigest: {client.DefaultRequestHeaders.GetValues("Digest").First()}\nx-request-id: {client.DefaultRequestHeaders.GetValues("X-Request-ID").First()}";
            var headerList    = "(request-target) date digest x-request-id";
            var signature     = Convert.ToBase64String(cert.GetRSAPrivateKey().SignData(Encoding.UTF8.GetBytes(signingString), HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1));

            var signatureHeader = (addSig ? "Signature " : "") + $"keyId=\"{keyId}\",algorithm=\"rsa-sha256\",headers=\"{headerList}\",signature=\"{signature}\"";

            client.DefaultRequestHeaders.Add(headerName, signatureHeader);
        }
예제 #8
0
        private SdkHttpClient GetClient()
        {
            SdkHttpClient client = GetSdkClient(apiUrl);

            client.DefaultRequestHeaders.Add("X-Client-Id", _settings.AppClientId);
            client.DefaultRequestHeaders.Add("X-Client-Secret", _settings.AppClientSecret);
            client.DefaultRequestHeaders.Add("X-Request-ID", Guid.NewGuid().ToString());

            return(client);
        }
예제 #9
0
        internal static void SignRequest(this SdkHttpClient client, HttpMethod method, string path, X509Certificate2 cert, string keyId)
        {
            var auth            = string.IsNullOrEmpty(client.DefaultRequestHeaders.Authorization?.Parameter) ? string.Empty : $"\nauthorization: {client.DefaultRequestHeaders.Authorization.Scheme} {client.DefaultRequestHeaders.Authorization.Parameter}";
            var signingString   = $"(request-target): {method.Method.ToLower()} {path}\nhost: {client.BaseAddress.Host}\ndigest: {client.DefaultRequestHeaders.GetValues("Digest").First()}\ndate: {client.DefaultRequestHeaders.GetValues("Date").First()}{auth}";
            var headerList      = $"(request-target) host digest date" + (string.IsNullOrEmpty(auth) ? string.Empty : " authorization");
            var signature       = Convert.ToBase64String(cert.GetRSAPrivateKey().SignData(Encoding.UTF8.GetBytes(signingString), HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1));
            var signatureHeader = $"keyId=\"{keyId}\",algorithm=\"rsa-sha256\",headers=\"{headerList}\",signature=\"{signature}\"";

            client.DefaultRequestHeaders.Add("Signature", signatureHeader);
        }
예제 #10
0
        private SdkHttpClient GetAuthClient()
        {
            SdkHttpClient sdkHttpClient = GetSdkClient(apiUrl);

            sdkHttpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            sdkHttpClient.DefaultRequestHeaders.Add("X-Request-ID", Guid.NewGuid().ToString());
            sdkHttpClient.DefaultRequestHeaders.TryAddWithoutValidation("Date", DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.ffffffZ"));

            return(sdkHttpClient);
        }
        internal static void SignRequest(this SdkHttpClient client, X509Certificate2 cert, HttpMethod method, string path, string keyId)
        {
            var signingString = $"(request-target): {method.Method.ToLower()} {path}\n(created): {GetNumericTime(DateTime.Now)}\n(expires): {GetNumericTime(DateTime.Now.AddSeconds(40))}\nx-request-id: {client.DefaultRequestHeaders.GetValues("X-Request-ID").First()}\ndigest: {client.DefaultRequestHeaders.GetValues("Digest").First()}";
            var headerList    = "(request-target) (created) (expires) host x-request-id digest";
            var signature     = Convert.ToBase64String(cert.GetRSAPrivateKey().SignData(Encoding.UTF8.GetBytes(signingString), HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1));

            var signatureHeader = $"signature:keyId=\"{keyId}\",algorithm=\"RS256\",headers=\"{headerList}\",signature=\"{signature}\"";

            client.DefaultRequestHeaders.Add("Signature", signatureHeader);
        }
예제 #12
0
        private SdkHttpClient GetClient(string payload = "")
        {
            SdkHttpClient sdkHttpClient = GetSdkClient(apiUrl);

            sdkHttpClient.DefaultRequestHeaders.Add("X-Openbank-Organization", "c0eb70e9-02ba-42f6-9736-bd4244c19c18");
            sdkHttpClient.DefaultRequestHeaders.Add("X-Openbank-Stet-Version", "1.4.0.47.develop");
            sdkHttpClient.DefaultRequestHeaders.Add("X-Request-ID", Guid.NewGuid().ToString());
            using (SHA256 sha256Hash = SHA256.Create())
            {
                sdkHttpClient.DefaultRequestHeaders.Add("Digest", "SHA-256=" + Convert.ToBase64String(sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(payload))));
            }
            return(sdkHttpClient);
        }
예제 #13
0
        private SdkHttpClient GetClient(string payload = "")
        {
            SdkHttpClient sdkHttpClient = GetSdkClient(apiUrl);

            sdkHttpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            sdkHttpClient.DefaultRequestHeaders.Add("X-Request-ID", Guid.NewGuid().ToString());
            sdkHttpClient.DefaultRequestHeaders.TryAddWithoutValidation("Date", DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.ffffffZ"));
            using (SHA256 sha256Hash = SHA256.Create())
            {
                sdkHttpClient.DefaultRequestHeaders.Add("Digest", "SHA-256=" + Convert.ToBase64String(sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(payload))));
            }
            return(sdkHttpClient);
        }
예제 #14
0
        private SdkHttpClient GetAuthClient()
        {
            SdkHttpClient sdkHttpClient = GetSdkClient(authUrl);

            sdkHttpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            sdkHttpClient.DefaultRequestHeaders.Add("X-Request-ID", Guid.NewGuid().ToString());

            if (SdkApiSettings.IsSandbox)
            {
                sdkHttpClient.DefaultRequestHeaders.Add("X-Openbank-Organization", "c0eb70e9-02ba-42f6-9736-bd4244c19c18");
            }
            sdkHttpClient.DefaultRequestHeaders.Add("X-Openbank-Stet-Version", "1.4.0.47.develop");

            return(sdkHttpClient);
        }
        private SdkHttpClient GetClient()
        {
            Console.Write("Je suis dans getClient :  URL ::     " + apiUrl + "     ");
            SdkHttpClient sdkHttpClient = GetSdkClient(apiUrl);

            Console.Write("Je suis dans getClient2");

            sdkHttpClient.DefaultRequestHeaders.Add("Request-ID", Guid.NewGuid().ToString());
            Console.Write("Je suis dans getClient3");

            sdkHttpClient.DefaultRequestHeaders.Add("Client-ID", _settings.AppClientId);
            Console.Write("Je suis dans getClient4");


            return(sdkHttpClient);
        }
예제 #16
0
 public abstract Credentials ProcessAuthParams(SdkHttpClient client, string regionId);