title: Pass in callback url when seeking request
body: <p>I'm adding twitter integration to my companies web application but I'm hitting a snag on it.</p>
  
  <p>The issue currently is with the callback url.</p>
  
  <p>In twitter it seems that it wants to have a set value but the way our application is setup, each customer that access the site has their own url.</p>
  
  <p>ideally I'd like to set the callback url on the fly, but I'm having a hard time finding any information on that.</p>
  
  <p>EDIT:
  Think I may need to add some more details here to better help you help me</p>
  
  <p>The issue is I setup the callback url parameter to <a href="https://api.twitter.com/oauth/request_token" rel="nofollow">https://api.twitter.com/oauth/request_token</a> but when I go to <a href="https://api.twitter.com/oauth/authorize" rel="nofollow">https://api.twitter.com/oauth/authorize</a> to get permission, it will go to the callback setup on the api, not what I set from the previous request.</p>
  
  <p>here is what my code looks like:</p>
  
  <pre><code>    public string oAuthToken(string callbackUrl)
      {
          Uri oauthUrl = new Uri("https://api.twitter.com/oauth/request_token");
          var oauthNonce = Convert.ToBase64String(new ASCIIEncoding().GetBytes(DateTime.Now.Ticks.ToString()));
          var oauthTimestamp = this.GenerateTimeStamp();
          var oauthSignature = "";
  
          var authSignature = string.Format("oauth_callback=\"{0}\"&amp;oauth_consumer_key=\"{1}\"&amp;oauth_nonce=\"{2}\"&amp;oauth_signature_method=\"{3}\"&amp;oauth_timestamp=\"{4}\"&amp;oauth_version=\"{5}\"",
              Uri.EscapeDataString(callbackUrl),
              Uri.EscapeDataString(this.ConsumerKey),
              Uri.EscapeDataString(oauthNonce),
              Uri.EscapeDataString(oauthSignatureMethod),
              Uri.EscapeDataString(oauthTimestamp),
              Uri.EscapeDataString(oauthVersion));
  
          var baseString = string.Format("POST&amp;{0}&amp;{1}", Uri.EscapeDataString(oauthUrl.AbsoluteUri), Uri.EscapeDataString(authSignature));
          var compositeKey = string.Concat(Uri.EscapeDataString(this.ConsumerSecret), "&amp;");
  
          using (HMACSHA1 hasher = new HMACSHA1(Encoding.ASCII.GetBytes(compositeKey)))
          {
              oauthSignature = Convert.ToBase64String(hasher.ComputeHash(Encoding.ASCII.GetBytes(baseString)));
          }
  
          var authHeader = string.Format("oauth oauth_callback=\"{0}\", oauth_consumer_key=\"{1}\", oauth_nonce=\"{2}\", oauth_signature=\"{3}\", oauth_signature_method=\"{4}\", oauth_timestamp=\"{5}\", oauth_version=\"{6}\"",
              Uri.EscapeDataString(callbackUrl),
              Uri.EscapeDataString(this.ConsumerKey),
              Uri.EscapeDataString(oauthNonce),
              Uri.EscapeDataString(oauthSignature),
              Uri.EscapeDataString(oauthSignatureMethod),
              Uri.EscapeDataString(oauthTimestamp),
              Uri.EscapeDataString(oauthVersion));
  
          ServicePointManager.Expect100Continue = false;
          HttpWebRequest authRequest = (HttpWebRequest)System.Net.WebRequest.Create(oauthUrl);
  
          authRequest.Method = "POST";
          authRequest.Headers.Add("Authorization", authHeader);
          authRequest.Headers.Add("Accept-Encoding", "gzip");
          authRequest.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
          authRequest.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
  
          try
          {
              using (var response = authRequest.GetResponse() as HttpWebResponse)
              {
                  if (response.StatusCode != HttpStatusCode.OK)
                  {
                      throw new Exception(String.Format("Server error (HTTP {0}: {1}).", response.StatusCode, response.StatusDescription));
                  }
  
                  var stream = response.GetResponseStream();
                  var sr = new StreamReader(stream);
                  return sr.ReadToEnd();
              }
          }
          catch (WebException ex)
          {
              using (var stream = ex.Response.GetResponseStream())
              using (var reader = new StreamReader(stream))
              {
                  return reader.ReadToEnd();
              }
          }
      }
  </code></pre>
  
  <p>I always get a 401 error back.</p>