【发布时间】:2017-06-22 06:32:15
【问题描述】:
我按照 openiddict 服务器示例中的说明使用来自https://github.com/openiddict/openiddict-samples/tree/master/samples/PasswordFlow 的密码流 但没有成功。
它抛出 InvalidOperationException: An OpenID Connect response cannot be returned from this endpoint at route /connect/token:
return SignIn(ticket.Principal, ticket.Properties, ticket.AuthenticationScheme);
邮递员参数:
- 内容类型: application/x-www-form-urlencoded
- 参数: username=..&password=...&grantType=password&scope=offline_access+profile+email
我花了一天的时间进行研究,但没有关于无法从此端点返回异常的信息。除了我之外,很多人都可以运行 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()
将抛出 OpenID Connect 请求无法从 ASP.NET 上下文中检索到。`
否则,去掉它,AuthorizationController中的OpenIdConnectRequest就可以正常获取了。而且我可以获取用户名、密码grantType等请求信息……奇怪……对吧?
其他一些信息:
- Asp.net Core SDK 1.1
- Project.json:https://gist.github.com/trinvh/47f29468887c209716098bc4c76181a7
- Startup.cs:https://gist.github.com/trinvh/75b7a12fbee754d0ea8cf251f2da9fe9
- AuthorizationController.cs:https://gist.github.com/trinvh/089015b2573cae550856631e72b81374
任何帮助将不胜感激!
【问题讨论】:
-
你发现'return SignIn()' 抛出了这个异常?
-
您是否还添加了ServiceConfiguration 中的services.AddIdentity 和services.AddOpenIddict
().AddMvcBinders() 以及Configure 中的必要内容? -
我尝试从其他人的存储库中运行一些示例代码,但遗憾的是它们也无法正常工作。我在 return SignIn 中设置了断点...所以我确定这里会抛出异常。很奇怪,每个人都跑得很好,但我不行!
-
是的,我按照 repo 页面上的说明进行操作。我也从其他来源获得代码,但无法正常工作。
-
我在这里发现了一个类似的问题:github.com/openiddict/openiddict-core/issues/252。 Pinpoint 可能有答案 ;-)