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.

TeknikRedirectUriValidator.cs 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using IdentityServer4.Models;
  2. using IdentityServer4.Validation;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Threading.Tasks;
  7. using Teknik.Configuration;
  8. namespace Teknik.IdentityServer.Security
  9. {
  10. public class TeknikRedirectUriValidator : IRedirectUriValidator
  11. {
  12. private readonly Config _config;
  13. public TeknikRedirectUriValidator(Config config)
  14. {
  15. _config = config;
  16. }
  17. public async Task<bool> IsPostLogoutRedirectUriValidAsync(string requestedUri, Client client)
  18. {
  19. if (client.PostLogoutRedirectUris != null && client.PostLogoutRedirectUris.Any())
  20. {
  21. if (client.PostLogoutRedirectUris.Contains(requestedUri))
  22. return true;
  23. }
  24. // Add special case for pre-configured redirect URIs
  25. if (client.ClientId == _config.UserConfig.IdentityServerConfig.ClientId &&
  26. _config.UserConfig.IdentityServerConfig.PostLogoutRedirectUris != null &&
  27. _config.UserConfig.IdentityServerConfig.PostLogoutRedirectUris.Any())
  28. {
  29. if (_config.UserConfig.IdentityServerConfig.PostLogoutRedirectUris.Contains(requestedUri))
  30. return true;
  31. }
  32. return false;
  33. }
  34. public async Task<bool> IsRedirectUriValidAsync(string requestedUri, Client client)
  35. {
  36. if (client.RedirectUris != null && client.RedirectUris.Any())
  37. {
  38. if (client.RedirectUris.Contains(requestedUri))
  39. return true;
  40. }
  41. // Add special case for pre-configured redirect URIs
  42. if (client.ClientId == _config.UserConfig.IdentityServerConfig.ClientId &&
  43. _config.UserConfig.IdentityServerConfig.RedirectUris != null &&
  44. _config.UserConfig.IdentityServerConfig.RedirectUris.Any())
  45. {
  46. if (_config.UserConfig.IdentityServerConfig.RedirectUris.Contains(requestedUri))
  47. return true;
  48. }
  49. return false;
  50. }
  51. }
  52. }