想要连接 Withings API。我在另一个项目中使用了相同的控制器,他工作得很好。在站点是 Azure webrole 的项目中(不知道这是怎么回事)它只是不起作用。首先我得到
'DotNetOpenAuth.Reporting' 的类型初始化程序引发了异常。
所以我在 web.config 中关闭了它
报告启用=“假”
现在我得到了
'DotNetOpenAuth.Logger' 的类型初始化程序引发了异常。
我不使用 log4net。
public ActionResult StartOAuth()
{
var serviceProvider = GetServiceDescription();
var consumer = new WebConsumer(serviceProvider, _tokenManager);
// Url to redirect to
var authUrl = new Uri(Request.Url.Scheme + "://" + Request.Url.Authority + "/Withings/OAuthCallBack");
// request access
consumer.Channel.Send(consumer.PrepareRequestUserAuthorization(authUrl, null, null));
// This will not get hit!
return null;
}
private ServiceProviderDescription GetServiceDescription()
{
return new ServiceProviderDescription
{
AccessTokenEndpoint = new MessageReceivingEndpoint("https://oauth.withings.com/account/access_token", HttpDeliveryMethods.PostRequest),
RequestTokenEndpoint = new MessageReceivingEndpoint("https://oauth.withings.com/account/request_token", HttpDeliveryMethods.PostRequest),
UserAuthorizationEndpoint = new MessageReceivingEndpoint("https://oauth.withings.com/account/authorize", HttpDeliveryMethods.PostRequest),
TamperProtectionElements = new ITamperProtectionChannelBindingElement[] { new HmacSha1SigningBindingElement() },
ProtocolVersion = ProtocolVersion.V10a
};
}