title: How to authenticate an API using OAuth1.0 with custom made header using Spring boot
body: <p>I am working on the OAuth1.0 authorization process and here is my Java code in Spring boot,</p>
  <pre><code>package com.example.demo;
  
  import com.mgiorda.oauth.OAuthConfig;
  import com.mgiorda.oauth.OAuthConfigBuilder;
  import com.mgiorda.oauth.OAuthSignature;
  import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  import org.springframework.context.annotation.ComponentScan;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.http.*;
  import org.springframework.web.client.RestTemplate;
  //import com.example.demo.testsign;
  import java.util.Collections;
  
  
  @SpringBootApplication
  @ComponentScan(basePackages = {&quot;com.example.demo.controller&quot;})
  @Configuration
  @EnableAutoConfiguration
  
  public class TestapiApplication {
      public  static String testm() {
  
          OAuthConfig oauthConfig = new OAuthConfigBuilder(&quot;CONSUMER KEY&quot;, &quot;CONSUM_SECRET_KEY&quot;)
                  .setTokenKeys(&quot;ACCESS TOKEN&quot;, &quot;SECRET TOKEN&quot;)
                  .build();
  
          OAuthSignature signature = oauthConfig.buildSignature(com.mgiorda.oauth.HttpMethod.GET, url)
                  .addQueryParam(&quot;aParam&quot;, &quot;aValue&quot;)
                  .addFormUrlEncodedParam(&quot;myParam&quot;, &quot;anotherValue&quot;)
                  .create();
          return signature.getAsHeader();
      }
  
      public static void main(String[] args) {
          String val = testm();
          //System.out.println(val);
          // request url
          String url = &quot;htpps://khjfskdhf.com&quot;;
  
  // create an instance of RestTemplate
          RestTemplate restTemplate = new RestTemplate();
  
  // create headers
          HttpHeaders headers = new HttpHeaders();
  // set `Content-Type` and `Accept` headers
          headers.setContentType(MediaType.APPLICATION_JSON);
          headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
  // example of custom header
  
          headers.set(HttpHeaders.AUTHORIZATION,val);
          System.out.println(headers);
  // build the request
          HttpEntity request = new HttpEntity(headers);
  
  // make an HTTP GET request with headers
          ResponseEntity&lt;String&gt; response = restTemplate.exchange(
                  url,
                  HttpMethod.GET,
                  request,
                  String.class
          );
  
  // check response
          if (response.getStatusCode() == HttpStatus.OK) {
              System.out.println(&quot;Request Successful.&quot;);
              System.out.println(response.getBody());
          } else {
              System.out.println(&quot;Request Failed&quot;);
              System.out.println(response.getStatusCode());
          }
      }
  
  }
  </code></pre>
  <p>I have created a header using the signature method and pass it to my main method to get authorized. But I got a 404 Not Found error, here is the error message,</p>
  <pre><code>08:13:17.464 [main] DEBUG org.springframework.web.client.RestTemplate - Response 404 NOT_FOUND
  Exception in thread &quot;main&quot; org.springframework.web.client.HttpClientErrorException$NotFound: 404 Not Found: [no body]
      at org.springframework.web.client.HttpClientErrorException.create(HttpClientErrorException.java:113)
      at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:184)
      at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:125)
      at org.springframework.web.client.ResponseErrorHandler.handleError(ResponseErrorHandler.java:63)
      at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:782)
      at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:740)
      at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:674)
      at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:583)
      at com.example.demo.TestapiApplication.main(TestapiApplication.java:61)
  </code></pre>
  <p>Could anyone let me know why its not working for me. I am really struggling to finish this up. Any suggestions?</p>
  <p>Thanks,
  Prabha</p>