The next generation of the Teknik Services. Written in ASP.NET. https://www.teknik.io/
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.

ConsentController.cs 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using IdentityServer4.Services;
  2. using IdentityServer4.Stores;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Microsoft.Extensions.Logging;
  5. using System;
  6. using System.Threading.Tasks;
  7. using Teknik.Configuration;
  8. using Teknik.IdentityServer.Models;
  9. using Teknik.IdentityServer.Security;
  10. using Teknik.IdentityServer.Services;
  11. using Teknik.Logging;
  12. namespace Teknik.IdentityServer.Controllers
  13. {
  14. /// <summary>
  15. /// This controller processes the consent UI
  16. /// </summary>
  17. public class ConsentController : DefaultController
  18. {
  19. private readonly ConsentService _consent;
  20. public ConsentController(
  21. ILogger<Logger> logger,
  22. Config config,
  23. IIdentityServerInteractionService interaction,
  24. IClientStore clientStore,
  25. IResourceStore resourceStore) : base(logger, config)
  26. {
  27. _consent = new ConsentService(interaction, clientStore, resourceStore, logger);
  28. }
  29. /// <summary>
  30. /// Shows the consent screen
  31. /// </summary>
  32. /// <param name="returnUrl"></param>
  33. /// <returns></returns>
  34. [HttpGet]
  35. public async Task<IActionResult> Index(string returnUrl)
  36. {
  37. ViewBag.Title = "Application Consent";
  38. var vm = await _consent.BuildViewModelAsync(returnUrl);
  39. if (vm != null)
  40. {
  41. return View("Index", vm);
  42. }
  43. throw new ApplicationException($"Unable to load consent view model.");
  44. }
  45. /// <summary>
  46. /// Handles the consent screen postback
  47. /// </summary>
  48. [HttpPost]
  49. [ValidateAntiForgeryToken]
  50. public async Task<IActionResult> Index(ConsentInputModel model)
  51. {
  52. var result = await _consent.ProcessConsent(model);
  53. if (result.IsRedirect)
  54. {
  55. return Redirect(result.RedirectUri);
  56. }
  57. if (result.HasValidationError)
  58. {
  59. ModelState.AddModelError("", result.ValidationError);
  60. }
  61. if (result.ShowView)
  62. {
  63. return View("Index", result.ViewModel);
  64. }
  65. throw new ApplicationException($"Unable to load consent view model.");
  66. }
  67. }
  68. }