title: Twitter request token OAuth 401 error
body: <p>Trying to add twitter login using OAuth and it has been a nightmare to get the first step of requesting the token, which results in 401 error as always.</p>
  
  <p>I used twitter's Test OAuth tool to compare the http request that my scala server sends.<br><strong>Curl</strong> request <strong>works</strong> while my <strong>server</strong> request <strong>fails</strong>. Pasting them below for comparison.<br><br>
  <strong>Curl Request</strong></p>
  
  <pre><code>curl --request 'POST' 'https://api.twitter.com/oauth/request_token' --data 'oauth_callback=http%3A%2F%2F0.0.0.0%3A8081%2Fweb' --header 'Authorization: OAuth oauth_consumer_key="wRflKWWomJ9jKeK8wbTk0Jck3", oauth_nonce="46ef029600fcc2a6cbe068eb9711401c", oauth_signature="3ptB%2B6%2Fv9QYGgyQjO9DhuD7pmzA%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1422879905", oauth_version="1.0"' --verbose
  </code></pre>
  
  <p><strong>Scala server Request</strong></p>
  
  <pre><code>HttpRequest(POST,https://api.twitter.com/oauth/request_token,List(Authorization: OAuth oauth_consumer_key="wRflKWWomJ9jKeK8wbTk0Jck3", oauth_nonce="70449464359328", oauth_signature="yEni23tuzEveIMtDm7%2F8N2anU%2FM%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1422879900", oauth_version="1.0"),HttpEntity(application/x-www-form-urlencoded,oauth_callback=http%3A%2F%2F0.0.0.0%3A8081%2Fweb),HTTP/1.1)
  </code></pre>
  
  <p><strong>Things I tried:</strong></p>
  
  <ul>
  <li>Made sure timestamp is within 5 minutes</li>
  <li>Made sure "<strong>Allow this
  application to be used to Sign in with Twitter</strong>" is set in twitter
  settings. </li>
  <li>Callback url is set - <a href="http://0.0.0.0:8081/web" rel="nofollow">http://0.0.0.0:8081/web</a> (even tried
  proxy names for localhost by changing ip table) </li>
  <li>Tried generating request token using <a href="https://github.com/scalaj/scalaj-http" rel="nofollow">Saclaj</a> </li>
  <li>Used custom OAuth signature request primarily using <a href="https://github.com/eigengo/activator-spray-twitter/blob/master/src/main/scala/core/OAuth.scala" rel="nofollow">OAuth.scala</a></li>
  </ul>
  
  <p>This 401 twitter request token seems to be a recurring theme for many folks, complicated by various failure points. Any help is much appreciated.</p>