Integration of Netsuite oAuth 1.0 Get API with HTTPCLIENT

32 views Asked by At

Postman Screenshot1 Postman Screenshot2

I'm currently working on integrating OAuth 1.0 authentication into my C# Web API project. I need to use the HMAC-SHA256 signature method, and I'm encountering issues with generating the correct OAuth header. I need to pass consumerKey,consumerSecret,accessToken,accessTokenSecret,realm to the request headers and i should not send timestamp and nonce with the headers

public class OAuth1HttpClient
    {
        private const string url = "";
        private const string consumerKey = "";
        private const string consumerSecret = "";
        private const string accessToken = "";
        private const string accessTokenSecret = "";
        private const string realm = "";

        public async Task<string> TestConnectionAsync()
        {
            using (HttpClient httpClient = new HttpClient())
            {
                
                var authorizationHeader = "oauth_consumer_key=" + Uri.EscapeDataString(consumerKey) + "&" +
                                         "oauth_signature_method=HMAC-SHA1&" +
                                         "oauth_token=" + Uri.EscapeDataString(accessToken) + "&" +
                                         "oauth_version=1.0" +
                                         "realm=\"" + Uri.EscapeDataString(realm) + "\"";

                httpClient.DefaultRequestHeaders.Add("Authorization", authorizationHeader);

                HttpResponseMessage response = httpClient.GetAsync(url).Result;

      string responseData =  response.Content.ReadAsStringAsync().Result;
                return responseData;

   }
 } 

0

There are 0 answers