1
我正在構建一個使用DotNetOpenAuth的OAuth服務提供程序,並對其進行測試我已經修改了示例wcf使用者以簡單地調用一個普通的http端點。令牌請求工作正常,但是當我請求訪問受保護的資源,我得到了以下協議execption:爲什麼我的DotNetOpenAuth使用者不尊重版本1.0a?
The following required parameters were missing from the DotNetOpenAuth.OAuth.Messages.AuthorizedTokenRequest message: oauth_verifier
當我看到日誌輸出我的服務提供商我看到這一點:
Error while performing basic validation of AuthorizedTokenRequest with these message parts:
oauth_token: pgzjBIs0pKCeDIcaIinyrV5Jhi0=
oauth_consumer_key: sampleconsumer
oauth_nonce: TM0Rc8kg
oauth_signature_method: HMAC-SHA1
oauth_signature: zmpxK5c69n1VzTEEcrnnd4e+qYI=
oauth_version: 1.0
oauth_timestamp: 1305067751
請注意oauth_version:1.0,即使我在創建使用者時指定了ProtocolVersion.V10a。
如果我雙方指定ProtocolVersion.V10我得到這個異常:
Expected message DotNetOpenAuth.OAuth.Messages.AccessProtectedResourceRequest but received DotNetOpenAuth.OAuth.Messages.AuthorizedTokenRequest instead.
這裏是消費代碼來獲取令牌(這是直接從示例代碼):
WebConsumer consumer = this.CreateConsumer();
UriBuilder callback = new UriBuilder(Request.Url);
callback.Query = null;
string[] scopes = (from item in this.scopeList.Items.OfType<ListItem>()
where item.Selected
select item.Value).ToArray();
string scope = string.Join("|", scopes);
var requestParams = new Dictionary<string, string> { { "scope", scope } };
var response = consumer.PrepareRequestUserAuthorization(callback.Uri, requestParams, null);
consumer.Channel.Send(response);
這裏是我的失敗消費代碼:
var accessToken = Session["WcfAccessToken"] as string;
var consumer = CreateConsumer();
var serviceEndpoint = new MessageReceivingEndpoint("https://mymachine/test/getUserName", HttpDeliveryMethods.AuthorizationHeaderRequest | HttpDeliveryMethods.PostRequest);
var httpRequest = consumer.PrepareAuthorizedRequest(serviceEndpoint, accessToken);
var httpResponse = httpRequest.GetResponse();
在我的服務提供商我叫SERV iceProvider.ReadProtectedResourceAuthorization();除了上面提到的例外,它失敗了。
任何想法我做錯了什麼?
你能拓展你的問題,包括對實際擺在首位獲得令牌消費者的源代碼? – 2011-05-11 13:20:02
我在我的問題中提到,我添加了獲取授權的調用,該部分使用的是DotNetOpenAuth附帶的示例中的OAuthConsumer SampleWcf.aspx頁面。 – 2011-05-11 16:02:18