So I've been working with DotNetOpenAuth for a while, Today I needed to add support for provider that forces me to send the secret key with Basic authentication (I've been using an old version and only Post parameters)
I've tried using ClientCredentialApplicator.NetworkCredential
, it didn't work. Then per the advice here, I've made my own ClientCredentialApplicator
.
I still didn't work, I put breakpoints in ApplyClientCredential
and they never hit.
I upgraded to the latest version (4.3.0.0), which should have this fix.
Everything works but there's no Authorization
header, and the remote server answers with 301 error (which makes me think it is the same problem as the commit - the Authorization info is not added to the request until the server answers with Unauthorized
and the provider I'm using answers with 301 when there's no Authorization
header)
Press Windows key + R and enter netplwiz. Now press Enter or click OK. Uncheck Users must enter a user name and password to use this computer. Now click OK and Apply to save changes.
In the Windows Credentials tab, expand the Network Credential entry and select Remove. Check if the network credentials work now. If removing the old entry didn't help, you should add a new entry for the credentials instead with the Add a Windows Credential option. Enter the network credentials and press OK.
Go to Control Panel > User accounts. From there, navigate to Credential Manager > Windows Credentials. You will see a field Add Windows Credentials, tap on it. In this menu, you can add the computer's name you want to access, username and password.
Here is the code. It works with me, when using WebClients and FtpWebRequests, e.t.c
using System.Net;
NetworkCredential credentials = new NetworkCredential("user","pass");
request.Credentials = credentials;
Hope it helps :)
I had a similar requirement: a OAuth2 provider that requires HTTP Basic Authentication. This solution worked for me:
var authServer = new AuthorizationServerDescription { AuthorizationEndpoint = new Uri(AuthorizeUrl), TokenEndpoint = new Uri(AccessTokenUrl) };
var authClient = new WebServerClient(authServer, ConsumerKey, ConsumerSecret)
{
ClientCredentialApplicator = ClientCredentialApplicator.NetworkCredential(ConsumerSecret)
};
There's an issue when using the DotNetOpenAuth.OAuth2.ClientCredentialApplicator.NetworkCredentialApplicator
constructor which takes an instance of System.Net.NetworkCredential
. The ApplyClientCredential
method uses the instance ClientSecret
property not the Password
property from the credentials (see below).
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);
}
I know this question is old, hoping this helps someone else searching for a solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With