Non ero in grado di far funzionare DNOA con OAuth a 2 vie, quindi ho finito per creare il mio consumer utilizzando http://oauth.googlecode.com/svn/code/csharp/OAuthBase.cs come classe base per gestire la firma. Tutto quello che devi fare è sottoclasse e utilizzare i metodi di firma per costruire l'intestazione di autorizzazione http ...
string sigMethodType = GetSigMethodType();
string ts, nonce, normalizedUrl, normalizedParams;
string sig = GenerateSignature(new Uri("http://some-endpoint-to-call"), "GET", out nonce, out ts, out normalizedUrl, out normalizedParams);
string header = "OAuth realm=\"" + normalizedUrl + "\"," +
OAuthConsumerKeyKey + "=\"" + ConsumerKey + "\"," +
OAuthSignatureMethodKey + "=\"" + "HMACSHA1SignatureType" + "\"," +
OAuthSignatureKey + "=\"" + sig + "\"," +
OAuthTimestampKey + "=\"" + ts + "\"," +
OAuthTokenKey + "=\"" + String.Empty + "\"," +
OAuthNonceKey + "=\"" + nonce + "\"," +
OAuthVersionKey + "=\"" + OAuthVersion + "\"";
Una volta che avete l'intestazione di autorizzazione solo a costruire la vostra richiesta web e inviarlo ...
var wr = (HttpWebRequest)HttpWebRequest.Create(messageEndpoint.Location);
wr.Headers.Add(HttpRequestHeader.Authorization, BuildAuthHeader(messageEndpoint));
wr.ContentType = messageEndpoint.ContentType;
wr.Method = CdwHttpMethods.Verbs[messageEndpoint.HttpMethod];
using (var resp = (HttpWebResponse)req.GetResponse())
{
switch (resp.StatusCode)
{
case HttpStatusCode.Unauthorized:
Assert.Fail("OAuth authorization failed");
break;
case HttpStatusCode.OK:
using (var stream = resp.GetResponseStream())
{
using (var sr = new StreamReader(stream))
{
var respString = sr.ReadToEnd();
}
}
break;
}
}
Aggiornamento: sono stato anche in grado di ottenere 2 gambe per lavorare con di devdefined utente OAuth. http://code.google.com/p/devdefined-tools/wiki/OAuthConsumer
var endPoint = new Uri("http://example.com/restendpoint.svc");
var ctx = new OAuthConsumerContext
{
ConsumerKey = "consumerkey1",
ConsumerSecret = "consumersecret1",
SignatureMethod = SignatureMethod.HmacSha1
};
var session = new OAuthSession(ctx, endPoint, endPoint, endPoint);
var respText = session.Request().Get().ForUri(endPoint).ToString();
Sarebbe bello se avesse un costruttore vuoto o di un sovraccarico che prende proprio nel contesto, ma questo sembra funzionare.
Hai mai risolto il modulo di autenticazione? Sto cercando qualcosa di simile. L'unica risposta qui è la creazione di un consumatore. – AlexGad