| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using System.Linq; |
| | | 4 | | using Microsoft.Extensions.Options; |
| | | 5 | | using System.Threading.Tasks; |
| | | 6 | | using IdentityServer4.AccessTokenValidation; |
| | | 7 | | using Microsoft.Extensions.DependencyInjection; |
| | | 8 | | using WinSolutions.Sveta.Server.Data.DataModel.Contexts; |
| | | 9 | | using WinSolutions.Sveta.Server.Data.DataModel.Entities; |
| | | 10 | | using Microsoft.Extensions.Configuration; |
| | | 11 | | using SVETA.Api.Data.DTO; |
| | | 12 | | using SVETA.Api.Data.Domain; |
| | | 13 | | using SVETA.Api.Helpers; |
| | | 14 | | using System.Text; |
| | | 15 | | |
| | | 16 | | namespace SVETA.Api.ConfigureOptions |
| | | 17 | | { |
| | | 18 | | public class ConfigureIdentityServerOptions : IConfigureNamedOptions<IdentityServerAuthenticationOptions> |
| | | 19 | | { |
| | | 20 | | private readonly IConfiguration _сonfiguration; |
| | | 21 | | private readonly AuthorizationSettings _authConfs; |
| | | 22 | | |
| | 0 | 23 | | public ConfigureIdentityServerOptions(IConfiguration сonfiguration, IOptions<AuthorizationSettings> authConfs) |
| | 0 | 24 | | { |
| | 0 | 25 | | _сonfiguration = сonfiguration; |
| | 0 | 26 | | _authConfs = authConfs.Value; |
| | 0 | 27 | | } |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// Конфигурирует настройки OIDC |
| | | 31 | | /// </summary> |
| | | 32 | | /// <param name="name"></param> |
| | | 33 | | /// <param name="options"></param> |
| | | 34 | | public void Configure(string name, IdentityServerAuthenticationOptions options) |
| | 0 | 35 | | { |
| | 0 | 36 | | if (name == IdentityServerAuthenticationDefaults.AuthenticationScheme) |
| | 0 | 37 | | { |
| | 0 | 38 | | options.Authority = _authConfs.IdentityUrl; |
| | 0 | 39 | | options.ApiName = _authConfs.ApiName; |
| | 0 | 40 | | options.ApiSecret = _authConfs.ApiSecret.Encrypted ? SymmetricCrypto.DecryptData(Convert.FromBase64Strin |
| | 0 | 41 | | options.RequireHttpsMetadata = false; |
| | 0 | 42 | | } |
| | 0 | 43 | | } |
| | | 44 | | |
| | | 45 | | // This won't be called, but is required for the IConfigureNamedOptions interface |
| | 0 | 46 | | public void Configure(IdentityServerAuthenticationOptions options) => Configure(Options.DefaultName, options); |
| | | 47 | | } |
| | | 48 | | } |