ASP.NET Core Openiddict throws “An OpenID Connect response cannot be returned from this endpoint”

非 Y 不嫁゛ 提交于 2019-12-06 09:20:29

Okay, here's what's happening:

  • You've configured OpenIddict to use /connect/token as the token endpoint address.
  • The token request you send via Postman points to /connect/token/, which is actually a totally different URL (/connect/token != /connect/token/).
  • Since the address differs from the registered endpoint path, OpenIddict doesn't handle the request and refuses to consider it as a token request.
  • For some reasons, MVC accepts to handle your /connect/token/ request and invokes the Exchange action, even though the route doesn't match the requested URL.
  • Since you haven't registered the OpenIddict MVC binder in the MVC options, MVC uses its default binder to construct the OpenIdConnectRequest object, which allows the OpenIdConnectRequest.GrantType parameter to be resolved from the invalid grantType parameter (it wouldn't happen with the dedicated OpenIddict binder).
  • Your token endpoint action ends up calling SignIn to return a token response.
  • Under the hood, OpenIddict detects that you called SignIn outside the normal token request processing - since it didn't consider the request as a token request, due to the paths difference - and aborts this unsafe operation by throwing an InvalidOperationException.

I'll ping the MVC folks to make sure they are aware of this bug.

Edit: after some research, it looks like this behavior is "by design" and was inherited from ASP.NET MVC. I opened a feature request in the aspnet/Mvc repository to add a new way to use "strict comparison" for routes matching.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!