需要代理身份验证(Forefront TMG 需要授权才能完成请求。对 Web 代理筛选器的访问被拒绝。)

发布于 2024-12-28 10:17:08 字数 959 浏览 2 评论 0原文

当我尝试向 Twitter 发布消息时,出现上述错误。如何消除该错误?

堆栈跟踪如下:

Exception = {“远程服务器返回错误:(407) 需要代理身份验证。”} ExceptionStatus = ProtocolError

代码:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

魔法少女 2025-01-04 10:17:08

如果 fluid twitter 在幕后使用 WebRequests,那么您需要使用如下代码指定代理的凭据:

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

这将告诉所有 Web 请求使用运行应用程序的用户的凭据来通过代理进行身份验证。

要实现此功能,您需要将应用程序配置为在已被授予代理服务器访问权限的服务帐户下运行。然后,您可以绑定此服务帐户,使其具有尽可能少的权限来运行该服务。

如果您的应用程序需要在无权使用代理服务器的帐户下运行,您可以明确指定凭据,如下所示:

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

这样做的缺点是您必须将这些凭据存储在某处,并且它们可能会被如果攻击者设法破坏您的应用程序,则会被攻击者捕获。在某些环境中,从安全角度来看这是不可接受的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文