我有一个类似的要求:需要HTTP Basic Authentication的 OAuth2 提供程序。这个解决方案对我有用:
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
凭据中的属性(见下文)。
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);
}
我知道这个问题很老,希望这可以帮助其他人寻找解决方案。