You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.1 KiB
74 lines
2.1 KiB
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
|
|
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
|
|
|
|
|
|
using IdentityServer4.Services;
|
|
using IdentityServer4.Stores;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Logging;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace IdentityServer4.Quickstart.UI
|
|
{
|
|
/// <summary>
|
|
/// This controller processes the consent UI
|
|
/// </summary>
|
|
[SecurityHeaders]
|
|
public class ConsentController : Controller
|
|
{
|
|
private readonly ConsentService _consent;
|
|
|
|
public ConsentController(
|
|
IIdentityServerInteractionService interaction,
|
|
IClientStore clientStore,
|
|
IResourceStore resourceStore,
|
|
ILogger<ConsentController> logger)
|
|
{
|
|
_consent = new ConsentService(interaction, clientStore, resourceStore, logger);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Shows the consent screen
|
|
/// </summary>
|
|
/// <param name="returnUrl"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<IActionResult> Index(string returnUrl)
|
|
{
|
|
var vm = await _consent.BuildViewModelAsync(returnUrl);
|
|
if (vm != null)
|
|
{
|
|
return View("Index", vm);
|
|
}
|
|
|
|
return View("Error");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Handles the consent screen postback
|
|
/// </summary>
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public async Task<IActionResult> Index(ConsentInputModel model)
|
|
{
|
|
var result = await _consent.ProcessConsent(model);
|
|
|
|
if (result.IsRedirect)
|
|
{
|
|
return Redirect(result.RedirectUri);
|
|
}
|
|
|
|
if (result.HasValidationError)
|
|
{
|
|
ModelState.AddModelError("", result.ValidationError);
|
|
}
|
|
|
|
if (result.ShowView)
|
|
{
|
|
return View("Index", result.ViewModel);
|
|
}
|
|
|
|
return View("Error");
|
|
}
|
|
}
|
|
} |