简体   繁体   中英

Proxy Authentication Required (Forefront TMG requires authorization to fulfill the request. Access to the Web Proxy filter is denied.)

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;
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM