私はGetClientAccessToken
フローを最新のリリース 4.1.0 (nuget 経由) で動作させようと試みてきました。ここでは、クライアント、承認サーバー、およびリソース サーバーの 3 つの関係者すべてを制御しています。
私がプロトタイプを作成し始めた状況は、Windows クライアント アプリ (私のクライアント - 最終的には WinRT になりますが、今はシンプルに保つために別の MVC 4 アプリです) と WebAPI プロジェクトのリソース セットです。現在、同じ WebAPI プロジェクトで部分的な承認サーバーをコントローラーとして公開しています。
毎回 (UserAgentClient や WebServerClient などのクライアントの種類に関係なく) GetClientAccessToken を試しますが、リクエストが認証サーバーに到達するまでに、リクエストの一部として clientIdentifier がないため、リクエストは次のように失敗します。
2012-10-15 13:40:16,333 [41 ] INFO {Channel} Prepared outgoing AccessTokenFailedResponse (2.0) message for <response>:
error: invalid_client
error_description: The client secret was incorrect.
ソースからDNOAにデバッグしましたが、基本的に、クライアントで確立している資格情報がNetworkCredential.ApplyClientCredential
内部で消去されていClientBase.RequestAccessToken
ます。clientIdentifier を適切なものに変更すると、コードの残りの部分を追跡して、正しいルックアップ/チェックが行われていることを確認できるので、認証サーバー コードが問題ないと確信できます。
私のテストクライアントは現在、次のようになっています。
public class AuthTestController : Controller
{
public static AuthorizationServerDescription AuthenticationServerDescription
{
get
{
return new AuthorizationServerDescription()
{
TokenEndpoint = new Uri("http://api.leave-now.com/OAuth/Token"),
AuthorizationEndpoint = new Uri("http://api.leave-now.com/OAuth/Authorise")
};
}
}
public async Task<ActionResult> Index()
{
var wsclient = new WebServerClient(AuthenticationServerDescription, "KieranBenton.LeaveNow.Metro", "testsecret");
var appclient = new DotNetOpenAuth.OAuth2.UserAgentClient(AuthenticationServerDescription, "KieranBenton.LeaveNow.Metro", "testsecret");
var cat = appclient.GetClientAccessToken(new[] { "https://api.leave-now.com/journeys/" });
// Acting as the Leave Now client we have access to the users credentials anyway
// TODO: CANNOT do this without SSL (turn off the bits in web.config on BOTH sides)
/*var state = client.ExchangeUserCredentialForToken("kieranbenton", "password", new[] { "https://api.leave-now.com/journeys/" });
// Attempt to talk to the APIs WITH the access token
var resourceclient = new OAuthHttpClient(state.AccessToken);
var response = await resourceclient.GetAsync("https://api.leave-now.com/journeys/");
string sresponse = await response.Content.ReadAsStringAsync();*/
// A wrong one
/*var wresourceclient = new OAuthHttpClient("blah blah");
var wresponse = await wresourceclient.GetAsync("https://api.leave-now.com/journeys/");
string wsresponse = await wresponse.Content.ReadAsStringAsync();
// And none
var nresourceclient = new HttpClient();
var nresponse = await nresourceclient.GetAsync("https://api.leave-now.com/journeys/");
string nsresponse = await nresponse.Content.ReadAsStringAsync();*/
return Content("");
}
}
これを防ぐ方法がわかりません。または、それが意図的に間違っているのかどうかもわかりません。
どんな助けでも感謝します。