【发布时间】:2016-04-26 22:12:33
【问题描述】:
在 AngularJS 中并使用 Chrome 高级 REST 客户端,我尝试使用基于 ASP.Net MVC 5 SPA Visual Studio 2015 模板的项目中的“密码”grant_type 获取令牌。该项目是全新的,完全没有任何修改。
使用此 URL 调用端点: http://localhost:55472/Token
[Headers]
Content-Type: application/x-www-form-urlencoded
Accept: application/json
[Encoded Payload]
Data:=grant_type%3Dpassword%26username%3Db%40c.d%26password%3DPass123--%26client_id%3Dweb
结果是这样的:
400 Bad Request
{"error":"invalid_client"}
没有配置外部登录,用户使用模板应用注册。
我尝试了不同的方法来构造这样的有效载荷并得到了相同的结果:
[Encoded Payload]
grant_type=password&username=b%40c.d&password=Pass123--&client_id=web
因此,可能是客户端没有正确调用端点:
var _tokenPath = '/Token';
var data = 'grant_type=password&username=b@c.d&password=Pass123--&client_id=web;
$http.post(_tokenPath, data, { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }).then(
function (response) {
debugger;
console.log(response);
},
function (error) {
debugger;
console.log(error);
}
)
或者 Startup.Auth.cs 文件中的某些内容不正确,导致端点无法正常工作。
我们如何在 MVC5 的 SPA 模板上获得开箱即用的 /Token url? 感谢您的帮助!
【问题讨论】:
-
这听起来有点远,但VS2013 SPA template had the same kind of problem。也许他们将伪造的模板复制到 VS2015 中,所以您需要从 NuGet 更新?
-
我从日志中得知它是一个无效的客户端 ID,发送到:Microsoft.Owin.Security.OAuth.OAuthAuthorizationServerMiddleware 错误:0:客户端 ID 无效。符号源上的此页面 (symbolsource.org/MyGet/Metadata/aspnetwebstacknightlyrelease/…) 确实在记录错误的地方拍摄。我需要知道的是,将客户端 ID 与什么进行比较?
-
@ÉtienneBrouillard,你能解决这个问题吗?如果可以,如何解决?我遇到了同样的问题,我需要让它工作。
-
@ClaytonHyatt 嗨,我从来没有解决过这个问题,我们在 NodeJS 上使用 OAuth2 服务器来让事情正常运行。
-
那真是太糟糕了!感谢您的回复。 ;)
标签: c# angularjs asp.net-mvc asp.net-mvc-5 owin