我想寫使用DotNetOpenAuth庫連接到使用OAuth的的 Evernote的沙盒一個C#ASP.NET MVC應用程序,但我無法得到它的工作。我的應用沒有問題,直到回調被調用,但是當我嘗試請求在this diagram的步驟10中交換臨時憑證時,它會以401未授權的方式失敗。如何讓OAuth使用DotNetOpenAuth和Evernote?
我的回調看起來是這樣的:在var accessTokenResponse = webConsumer.ProcessUserAuthorization();
線,是什麼企圖憑證交流發生
public ActionResult OAuthCallback()
{
var webConsumer = CreateWebConsumer();
var accessTokenResponse = webConsumer.ProcessUserAuthorization();
if (accessTokenResponse != null)
{
AccessToken = accessTokenResponse.AccessToken;
}
return RedirectToAction("Index");
}
的異常。
提琴手顯示以下內容:
調用回調:
GET http://localhost:22297/Home/OAuthCallback?oauth_token=GiddyUpHorsey.13F82BDC264.687474703A2F2F6C6F63616C686F73743A32323239372F486F6D652F4F4175746843616C6C6261636B.CFB67142944B4EB90148DDAFE2120A71&oauth_verifier=93534C2B04F862E57B30D738C3569242 HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Connection: Keep-Alive
Accept-Language: en-NZ
User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)
Pragma: no-cache
Accept-Encoding: gzip, deflate
Host: localhost:22297
DNT: 1
Cache-Control: no-cache
請求令牌交換:
通過webConsumer.ProcessUserAuthorization();
觸發。
POST https://sandbox.evernote.com/oauth HTTP/1.1
Content-Type: application/x-www-form-urlencoded; charset=utf-8
User-Agent: DotNetOpenAuth.Core/4.3.0.13117
Host: sandbox.evernote.com
Cache-Control: no-store,no-cache
Pragma: no-cache
Content-Length: 369
Expect: 100-continue
oauth_verifier=93534C2B04F862E57B30D738C3569242&oauth_token=GiddyUpHorsey.13F82BDC264.687474703A2F2F6C6F63616C686F73743A32323239372F486F6D652F4F4175746843616C6C6261636B.CFB67142944B4EB90148DDAFE2120A71&oauth_consumer_key=GiddyUpHorsey&oauth_nonce=cHABo5jv&oauth_signature_method=PLAINTEXT&oauth_signature=4c0dd81215379f75%26&oauth_version=1.0&oauth_timestamp=1372288061
響應:
HTTP/1.1 401 Unauthorized
Set-Cookie: JSESSIONID=4CDCD690AEAD69D952CEE4CBED5AC8DC; Path=/
Content-Type: text/html;charset=ISO-8859-1
Content-Language: en
Date: Wed, 26 Jun 2013 23:07:48 GMT
Server: Evernote/1.0
Content-Length: 1587
<html>
.....
<div class="page-header">
<h1>
Oops, we encountered an error.</h1>
</div>
<div>
<p>
Sorry, we've encountered an unexpected error.</p>
</div>
<div class="clear"></div>
</div>
...
</html>
(我去掉了大部分的HTML從響應)
爲什麼會失敗,401授權?
我想你的代碼和奇怪的是,我仍然得到401未經授權錯誤。我想知道這個問題是否與我的環境有關。該應用程序必須通過代理服務器與外部世界進行通信。也許這與它有關。 – GiddyUpHorsey
你在哪一步得到401錯誤?用戶看到401還是在GetRequestToken期間發生? –
它在調用https://sandbox.evernote.com/oauth這一行時發生:'var result = await base.GetAccessToken(OAuthUrl,token,oauth_verifier,null,null);'AsyncEvernoteoryAuthorizer.cs:Line 115。用戶已在Evernote中授權應用程序,然後發生錯誤。用戶看到有關401 Unauthorized異常的YSOD。 – GiddyUpHorsey