我一直在尝试让GetClientAccessToken
流程与最新版本 4.1.0(通过 nuget)一起工作,我可以控制所有三方:客户端、授权服务器和资源服务器。
我开始原型化的情况是一个 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
inside清除了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("");
}
}
我不知道如何防止这种情况,或者如果它是设计使我做错了什么。
任何帮助表示赞赏。