Browse Source

Add Debug.Assert checks to help diagnose OpenIdConnectRequest model binding issues

pull/303/head
Kévin Chalet 9 years ago
parent
commit
1a5eed3f3a
  1. 17
      samples/Mvc.Server/Controllers/AuthorizationController.cs

17
samples/Mvc.Server/Controllers/AuthorizationController.cs

@ -4,6 +4,7 @@
* the license and the contributors participating to this project.
*/
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using AspNet.Security.OpenIdConnect.Extensions;
@ -42,6 +43,10 @@ namespace Mvc.Server {
[Authorize, HttpGet("~/connect/authorize")]
public async Task<IActionResult> Authorize(OpenIdConnectRequest request) {
Debug.Assert(request.IsAuthorizationRequest(),
"The OpenIddict binder for ASP.NET Core MVC is not registered. " +
"Make sure services.AddOpenIddict().AddMvcBinders() is correctly called.");
// Retrieve the application details from the database.
var application = await _applicationManager.FindByClientIdAsync(request.ClientId, HttpContext.RequestAborted);
if (application == null) {
@ -63,6 +68,10 @@ namespace Mvc.Server {
[Authorize, FormValueRequired("submit.Accept")]
[HttpPost("~/connect/authorize"), ValidateAntiForgeryToken]
public async Task<IActionResult> Accept(OpenIdConnectRequest request) {
Debug.Assert(request.IsAuthorizationRequest(),
"The OpenIddict binder for ASP.NET Core MVC is not registered. " +
"Make sure services.AddOpenIddict().AddMvcBinders() is correctly called.");
// Retrieve the profile of the logged in user.
var user = await _userManager.GetUserAsync(User);
if (user == null) {
@ -92,6 +101,10 @@ namespace Mvc.Server {
[HttpGet("~/connect/logout")]
public IActionResult Logout(OpenIdConnectRequest request) {
Debug.Assert(request.IsLogoutRequest(),
"The OpenIddict binder for ASP.NET Core MVC is not registered. " +
"Make sure services.AddOpenIddict().AddMvcBinders() is correctly called.");
// Flow the request_id to allow OpenIddict to restore
// the original logout request from the distributed cache.
return View(new LogoutViewModel {
@ -118,6 +131,10 @@ namespace Mvc.Server {
[HttpPost("~/connect/token"), Produces("application/json")]
public async Task<IActionResult> Exchange(OpenIdConnectRequest request) {
Debug.Assert(request.IsTokenRequest(),
"The OpenIddict binder for ASP.NET Core MVC is not registered. " +
"Make sure services.AddOpenIddict().AddMvcBinders() is correctly called.");
if (request.IsPasswordGrantType()) {
var user = await _userManager.FindByNameAsync(request.Username);
if (user == null) {

Loading…
Cancel
Save