【问题标题】:dotnetOpenAuth fails on protocol error. Is it ServiceProviderDescription ot TokenManager?dotnetOpenAuth 因协议错误而失败。是 ServiceProviderDescription 还是 TokenManager?
【发布时间】:2012-03-02 18:37:54
【问题描述】:

为什么我会得到openAuth protocol error

{"远程服务器返回错误:(400) Bad Request."}

在 System.Net.HttpWebRequest.GetResponse() 在 DotNetOpenAuth.Messaging.StandardWebRequestHandler.GetResponse(HttpWebRequest 请求,DirectWebRequestOptions 选项)在 c:\BuildAgent\work\a02b428f36957bca\src\DotNetOpenAuth\Messaging\StandardWebRequestHandler.cs:line 126

    public static readonly ServiceProviderDescription ServiceDescription = new  ServiceProviderDescription
{
    RequestTokenEndpoint = 
       new MessageReceivingEndpoint("https://www.google.com/account/OAuthGetRequestToken", HttpDeliveryMethods.AuthorizationHeaderRequest | HttpDeliveryMethods.GetRequest),
    UserAuthorizationEndpoint = 
       new MessageReceivingEndpoint("https://www.google.com/accounts/OAuthAuthorizeToken",
HttpDeliveryMethods.AuthorizationHeaderRequest | HttpDeliveryMethods.GetRequest),
    AccessTokenEndpoint = 
       new MessageReceivingEndpoint("https://www.google.com/accounts/OAuthGetAccessToken", HttpDeliveryMethods.AuthorizationHeaderRequest | HttpDeliveryMethods.GetRequest),
    TamperProtectionElements = 
       new ITamperProtectionChannelBindingElement[] { new HmacSha1SigningBindingElement() },
  };



public void StartOAuth()
{
    var consumer = new WebConsumer(GoogleConsumer.ServiceDescription, new InMemoryTokenManager("user", "pass"));
 // Url to redirect to
    var authUrl = new Uri("http://www.google.com");
 // request access
    consumer.Channel.Send(consumer.PrepareRequestUserAuthorization(authUrl, null, null));

      throw new NoRedirectToAuthPageException();
     }

【问题讨论】:

    标签: c# asp.net asp.net-mvc dotnetopenauth


    【解决方案1】:

    我不知道这是否会导致您看到的错误,但是您将 Google 自己的 URL 作为回调 URL 传入?这似乎是错误的。您需要将 URL 传递给您自己的站点(将调用 WebConsumer.ProcessUserAuthorization 的站点)作为 PrepareRequestUserAuthorization 方法的第一个参数。

    我还注意到您的请求令牌 URL 中缺少一个“s”:https://www.google.com/account*s*/OAuthGetRequestToken

    这很可能会破坏它。

    【讨论】:

    • 我仍然在本地主机上运行。尝试更改为某些本地主机 url,但没有帮助。我想使用 DNOA,但我认为它在 matlus.com/oauth-c-library 中出现的标题中缺少某些内容
    • 更新了可能的罪魁祸首的答案。
    猜你喜欢
    • 2014-02-26
    • 2012-01-31
    • 2019-07-03
    • 2017-01-09
    • 2020-04-15
    • 1970-01-01
    • 2016-05-19
    • 2011-08-12
    • 2019-01-14
    相关资源
    最近更新 更多