【问题标题】:Salesforce DotNetOpenAuth / Oauth Remote Access ProblemsSalesforce DotNetOpenAuth / Oauth 远程访问问题
【发布时间】:2011-02-26 03:16:14
【问题描述】:

我正在尝试使用 Oauth 从 .NET 应用程序连接到 salesforce。我目前正在使用 DotNetOpenAuth,但没有运气。我可以让 twitter / google 等正常工作,但是当我为 Salesforce 创建新的消费者服务时,它只会给我一个错误(400 / Bad Request)

我正在使用 InMemoryTokenManager,但在我被骂之前,让我重申一下 twitter 等人以这种方式工作正常。我确实打算用数据库实现替换 inmemorytoken 管理器,但现在我只想让它工作。

奇怪的是,如果我手动创建 URL - https://login.salesforce.com/services/oauth2/authorize?response_type=code&client_id=[consumer_key]&redirect_uri=[redirect_url]并在浏览器中输入它,我最终进入了一个销售人员页面,以授权该应用程序访问我的帐户——如果一切正常,我希望看到这个页面。

这是预期的行为吗?这似乎是一个安全漏洞,但也许我没有正确理解所有内容。

任何想法我哪里出错了?

ConsumerCode - (嗯,至少是重要的部分)

public static readonly ServiceProviderDescription ServiceDescription = new ServiceProviderDescription
{
    RequestTokenEndpoint = 
        new MessageReceivingEndpoint(
        "https://login.salesforce.com/services/oauth2/authorize", 
        HttpDeliveryMethods.GetRequest | 
        HttpDeliveryMethods.AuthorizationHeaderRequest),
    UserAuthorizationEndpoint = 
        new MessageReceivingEndpoint(
        "https://login.salesforce.com/services/oauth2/authorize", 
        HttpDeliveryMethods.GetRequest | 
        HttpDeliveryMethods.AuthorizationHeaderRequest),
    AccessTokenEndpoint = 
        new MessageReceivingEndpoint(
        "https://login.salesforce.com/services/oauth2/token", 
        HttpDeliveryMethods.GetRequest | 
        HttpDeliveryMethods.AuthorizationHeaderRequest),
    TamperProtectionElements = 
    new ITamperProtectionChannelBindingElement[] { 
    new HmacSha1SigningBindingElement() },
}; 

OAuthController.cs

if (this.SFTokenManager != null)
{
    var SF = new WebConsumer(SFConsumer.ServiceDescription, this.SFTokenManager);
    // Is Twitter calling back with authorization?
    var accessTokenResponse = SF.ProcessUserAuthorization();
    if (accessTokenResponse != null)
    {
        this.SFAccessToken = accessTokenResponse.AccessToken;
    }
    else if (this.SFAccessToken == null)
    {
        // If we don't yet have access, immediately request it.
        SF.Channel.Send(SF.PrepareRequestUserAuthorization());                    
    }
    return View("SFIn");
}
else
{
    return View("SFOut");
}

我得到 400 的那一行是

// If we don't yet have access, immediately request it.
SF.Channel.Send(SF.PrepareRequestUserAuthorization());   

【问题讨论】:

  • 听起来您可能正在使用 oAuth1 客户端,但调用的是 oAuth2 端点。

标签: oauth dotnetopenauth salesforce


【解决方案1】:

DotNetOpenAuth 说它的 oAuth 支持是 1.0 和 1.0a,当您尝试访问 Salesforce 的 oAuth 2.0 服务时,这两种协议不兼容。

【讨论】:

  • oAuth2 很简单,你应该可以直接使用它,不需要任何工具包。
  • 感谢 superfell,但是我也尝试了 oAuth 1.0 端点并得到了相同的响应 - 400 / 错误请求。在错误的协议开始导致问题之前很久就出现了问题。
  • 我被这篇文章推迟了 [rumbleware.com/blog/2009/10/…,它建议使用一个库,尽管它似乎也指的是 OAuth1.0,它似乎更复杂
  • 有关手动实现 OAuth 2.0 的示例,请参阅 wiki.developerforce.com/index.php/…developer.force.com/cookbook/recipe/… - 这样做比使用 Ruby OAuth2 库更容易。
【解决方案2】:

我对 SalesForce 一无所知,但从您的消息看来,SalesForce 使用 OAuth 2.0。但是您使用的是 DotNetOpenAuth 的 OAuth 1.0(a) 功能,这可以解释它失败的原因。

您可以尝试使用 OAuth 2.0 CTP version of DotNetOpenAuth 并使用 OAuth 2.0 的新 API 看看是否有帮助。

【讨论】:

    【解决方案3】:

    【讨论】:

      猜你喜欢
      • 2012-06-16
      • 1970-01-01
      • 1970-01-01
      • 2016-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多