我使用来自https://github.com/openiddict/openiddict-samples/tree/master/samples/PasswordFlow的密码流来遵循openiddict服务器示例中的说明 但没有成功。
抛出 InvalidOperationException:无法在路径 / connect / token 处从此端点返回OpenID Connect响应:
return SignIn(ticket.Principal, ticket.Properties, ticket.AuthenticationScheme);
Postman params:
我花了一天时间进行研究,但没有关于无法从此端点返回异常的信息。除了我以外,很多人都可以运行openiddict示例。
这是Startup.cs的一部分:
services.AddEntityFrameworkSqlite()
.AddDbContext<MisapayContext>(options =>
{
options.UseOpenIddict<int>();
});
//....
services.AddOpenIddict<int>()
.AddEntityFrameworkCoreStores<MisapayContext>()
.DisableHttpsRequirement()
.EnableTokenEndpoint("/connect/token")
.EnableLogoutEndpoint("/connect/logout")
.EnableUserinfoEndpoint("/connect/userinfo")
.UseJsonWebTokens()
.AllowPasswordFlow()
.AllowRefreshTokenFlow()
.AddEphemeralSigningKey();
services.AddMvc(config =>
{
config.Filters.Add(new ApiExceptionFilter());
}).AddJsonOptions(options =>
{
options.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented;
options.SerializerSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Local;
});
编辑:我认为问题是 OpenIdConnectRequest ,如果使用它就无法绑定:
OpenIddictBuiler.AddMvcBinders()
将抛出无法从ASP.NET上下文中检索OpenID Connect请求。
否则,删除它,AuthorizationController中的OpenIdConnectRequest可以正常获取。我可以获得请求信息,如用户名,密码grantType等......奇怪......对吗?
其他一些信息:
任何帮助将不胜感激!
答案 0 :(得分:3)
好的,这里发生了什么:
/connect/token
作为令牌端点地址。/connect/token/
,这实际上是一个完全不同的网址(/connect/token
!= /connect/token/
)。/connect/token/
请求并调用Exchange
操作,即使该路由与请求的网址不匹配。OpenIdConnectRequest
对象,这允许从无效的OpenIdConnectRequest.GrantType
参数中解析grantType
参数(使用专用的OpenIddict游戏块不会发生这种情况)。SignIn
以返回令牌响应。SignIn
- 因为由于路径不同,它没有将请求视为令牌请求 - 并且中止此不安全操作通过抛出InvalidOperationException
。我会ping MVC人员,以确保他们知道这个错误。
编辑经过一些研究,看起来这种行为是&#34;设计&#34;并继承自ASP.NET MVC。我打开a feature request in the aspnet/Mvc repository添加了一种新的使用方式&#34;严格比较&#34;路线匹配。