与ASP身份2向/令牌端点时,一定要接受“invalid_client”错误 [英] Always receiving 'invalid_client' error when POSTing to /Token endpoint with ASP Identity 2
问题描述
大约一个月前,我做了一个项目,ASP身份OAuth的工作完美。我会发送POST请求到/令牌端点grant_type,用户名和密码,一切都是花花公子。
About a month ago I had a project working perfectly with ASP Identity OAuth. I'd send a POST request to the /Token endpoint with grant_type, username, and password, and all was dandy.
最近,我开始了基础的Visual Studio 2013 RC2的SPA模板的新项目。它比旧模板有点不同。身份验证设置为pretty基本默认值,
I recently started a new project based off of Visual Studio 2013 RC2's SPA template. It's a bit different than the old template. Authentication is set up to pretty basic defaults,
OAuthOptions = new OAuthAuthorizationServerOptions
{
TokenEndpointPath = new PathString("/Token"),
//AuthorizeEndpointPath = new PathString("/Account/Authorize"),
Provider = new ApplicationOAuthProvider(PublicClientId),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
AllowInsecureHttp = true
};
没有显著从默认模板修改。
Nothing significant changed from the default template. I can register accounts successfully through a Web API controller method I have implemented;
// POST: /Account/Register
[HttpPost]
[AllowAnonymous]
public async Task<IHttpActionResult> Register(RegisterBindingModel model)
{
if (ModelState.IsValid)
{
var user = new TunrUser() { UserName = model.Email, Email = model.Email, DisplayName = model.DisplayName };
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
return Created(new Uri("/api/Users/" + user.Id,UriKind.Relative), user.toViewModel());
}
else
{
return BadRequest(result.Errors.First());
}
}
return BadRequest(ModelState);
}
不过,无论怎样我发布到/令牌终点,我的总是的获得同样的反应。
{"error":"invalid_client"}
通常我通过以下请求主体
Normally I pass the following request body
grant_type=password&username=user%40domain.com&password=userpassword
但是,这将导致同样的错误。这个工作在previous VS2013 SPA模板/身份。什么改变?
But this results in the same error. This worked in the previous VS2013 SPA template / Identity. What's changed?
感谢您!
推荐答案
因此,原来,新模板不包括ApplicationOAuthProvider的功能实现,在旧模板present。
So it turns out that the new templates don't include a functional implementation of ApplicationOAuthProvider that was present in the older templates.
此版本谈话之后,我进一步调查后发现, ApplicationOAuthProvider的工作实施提供这个包的NuGet !它非常类似于旧的实现。
After watching this build talk, I investigated further and found that a working implementation of ApplicationOAuthProvider is available to check out in this NuGet package! It's very similar to the old implementation.
这篇关于与ASP身份2向/令牌端点时,一定要接受“invalid_client”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!