【发布时间】: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