CyberSource / cybersource-rest-client-dotnetstandard

.NET Standard client library for the CyberSource REST API
7 stars 15 forks source link

Add configuration setting to set RestClient url and Host header independently of RunEnvironment setting #26

Open wopietrz opened 2 years ago

wopietrz commented 2 years ago

I'm trying to call Cybersource Rest Api via Azure Api Management to meet security and complaince requirements. Unfortunately I run into some issues:

  1. I' m not able to set RestClient Url to Api Management endpoint independently of RunEnviroment setting.
  2. I'm not able to modify the Host header independently of RunEnviroment setting to establish ssl connection.
  3. When I set the value of RunEnvironemnt to Azure Api Management endpoint then it is possilbe to connect to APIM but, Cybersource refuses a request becasue of inccorrect value of Signature header

There is a possibility to initialize RestClient with a custom url, however in ApiClient.CallAuthtenticationHeaders the RestClient property is recreated:

ApiClient.cs:

    public void CallAuthenticationHeaders(string requestType, string requestTarget, string requestJsonData = null)
    {
       ...

        Configuration.DefaultHeader = authenticationHeaders;
        RestClient = new RestClient("https://" + merchantConfig.HostName);

        if (Configuration.Proxy != null)
        {
            RestClient.Proxy = Configuration.Proxy;
        }
    }

In above code merchantConfig.HostName points to RunEnvironement setting.

wopietrz commented 1 year ago

Pull Request with changes proposal: https://github.com/CyberSource/cybersource-rest-client-dotnetstandard/pull/45

sebastian-sawicki commented 1 year ago

This issue is related with issue https://github.com/CyberSource/cybersource-rest-client-dotnetstandard/issues/39 which also points to CallAuthenticationHeaders where new instance of RestClient is recreated.

I raise also separate https://github.com/CyberSource/cybersource-rest-client-dotnetstandard/issues/46 "Update RestSharp to v107 and follow recommended usage".