3

When I was trying to post messages to Twitter, the above error coming. How to get rid of that error?

The stacktrace is the following:

Exception = {"The remote server returned an error: (407) Proxy Authentication Required."} ExceptionStatus = ProtocolError

Code:

private string GetOAuthUrl()
{
    IFluentTwitter twitter;

    //Override the callback url if one was entered
    if (CallbackUrl != null && CallbackUrl.Trim().Length > 0)
    {
        twitter = FluentTwitter.CreateRequest().Configuration.UseHttps().Authentication.GetRequestToken(ConsumerKey, ConsumerSecret, CallbackUrl);
    }
    else
    {
        twitter = FluentTwitter.CreateRequest().Configuration.UseHttps().Authentication.GetRequestToken(ConsumerKey, ConsumerSecret);
    }

    var response = twitter.Request();
    UnauthorizedToken UnauthorizedToken = response.AsToken();

    string AuthorizationUrl = FluentTwitter.CreateRequest().Authentication.GetAuthorizationUrl(UnauthorizedToken.Token);
    return AuthorizationUrl;
}
palacsint
  • 28,416
  • 10
  • 82
  • 109
user1157685
  • 41
  • 1
  • 1
  • 6

1 Answers1

7

If fluent twitter is using WebRequests under the covers, then you need to specify credentials for the proxy using code like this:

 System.Net.WebRequest.DefaultWebProxy.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;

This will tell all web requests to use the credentials of the user running the application to authenticate with the proxy.

To make this work, you will need to configure the application to run under a service account which has been granted access to the proxy server. You can then tie down this service account so that it has as few permissions as possible to run the service.

If your application needs to run under an account which doesn't have rights to use the proxy server, you can specify the credentials explicitly as follows:

System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("username", "password", "domain");
System.Net.WebRequest.DefaultProxy.Credentials = credentials;

The down side to this is that you have to store those credentials somewhere, and that they could be captured by an attacker if they managed to compromise your application. In some environments, this is not acceptable from a security standpoint.

sga101
  • 1,904
  • 13
  • 12
  • it is not working,in debug mode i found username password,domain is null – user1157685 Jan 30 '12 at 11:21
  • It is likely that your application is running under a local account. You will either need to change the account, or specify credentials explicitly from your code. I have amended my answer accordingly. – sga101 Jan 30 '12 at 11:44
  • ya my application is running under a local account, i cant change the account,i will try using this code,i will try this ,can u tell me should i make in web config file, domain what should be used there – user1157685 Jan 30 '12 at 12:28
  • See this answer for details on how to specify credentials in web.config: http://stackoverflow.com/questions/186800/is-it-possible-to-specify-proxy-credentials-in-your-web-config. Make sure they are encrypted, and the account used has the least permissions possible (i.e don't use your own credentials) – sga101 Jan 30 '12 at 13:39