我有类似的需求:需要一个OAuth2提供程序,需要
HTTP基本身份验证。这个解决方案对我很有效。
var authServer = new AuthorizationServerDescription { AuthorizationEndpoint = new Uri(AuthorizeUrl), TokenEndpoint = new Uri(AccessTokenUrl) }
var authClient = new WebServerClient(authServer, ConsumerKey, ConsumerSecret)
{
ClientCredentialApplicator = ClientCredentialApplicator.NetworkCredential(ConsumerSecret)
}
使用
DotNetOpenAuth.OAuth2.ClientCredentialApplicator.NetworkCredentialApplicator
构造函数时存在问题,该构造函数需要一个
System.Net.NetworkCredential
实例。在
ApplyClientCredential
方法中,使用的是凭据中
ClientSecret
属性而不是
Password
属性(请参见下文)。请注意保留HTML标签。
public override void ApplyClientCredential(string clientIdentifier, HttpWebRequest request)
{
if (clientIdentifier == null)
return;
if (this.credential != null)
ErrorUtilities.VerifyHost((string.Equals(this.credential.UserName, clientIdentifier, StringComparison.Ordinal) ? 1 : 0) != 0, "Client identifiers \"{0}\" and \"{1}\" do not match.", (object) this.credential.UserName, (object) clientIdentifier);
OAuthUtilities.ApplyHttpBasicAuth(request.Headers, clientIdentifier, this.clientSecret);
}
我知道这个问题很久远了,希望这能帮助其他正在寻找解决方案的人。