|
3 | 3 |
|
4 | 4 | using System.Diagnostics.CodeAnalysis; |
5 | 5 | using System.IdentityModel.Tokens.Jwt; |
6 | | -using System.Security.Cryptography.X509Certificates; |
7 | 6 | using Microsoft.AspNetCore.Authentication.JwtBearer; |
8 | | -using Microsoft.AspNetCore.DataProtection; |
9 | 7 | using Microsoft.Identity.Web.Sidecar.Endpoints; |
10 | 8 | using Microsoft.IdentityModel.JsonWebTokens; |
11 | 9 |
|
@@ -49,8 +47,6 @@ public static void Main(string[] args) |
49 | 47 | }); |
50 | 48 | } |
51 | 49 |
|
52 | | - ConfigureDataProtection(builder); |
53 | | - |
54 | 50 | // Add the agent identities and downstream APIs |
55 | 51 | builder.Services.AddAgentIdentities() |
56 | 52 | .AddDownstreamApis(builder.Configuration.GetSection("DownstreamApis")); |
@@ -103,40 +99,4 @@ private static void ConfigureAuthN(WebApplicationBuilder builder) |
103 | 99 | options.TokenValidationParameters.NameClaimType = "sub"; |
104 | 100 | }); |
105 | 101 | } |
106 | | - |
107 | | - private static void ConfigureDataProtection(WebApplicationBuilder builder) |
108 | | - { |
109 | | - var dataProtectionBuilder = builder.Services.AddDataProtection() |
110 | | - .SetApplicationName("Microsoft.Identity.Web.Sidecar"); |
111 | | - |
112 | | - // Configure based on environment |
113 | | - if (builder.Environment.IsProduction()) |
114 | | - { |
115 | | - // Production configuration for Linux containers |
116 | | - var keysPath = Environment.GetEnvironmentVariable("DATA_PROTECTION_KEYS_PATH") ?? "/app/keys"; |
117 | | - |
118 | | - // Ensure the directory exists |
119 | | - Directory.CreateDirectory(keysPath); |
120 | | - |
121 | | - dataProtectionBuilder.PersistKeysToFileSystem(new DirectoryInfo(keysPath)); |
122 | | - |
123 | | - // Optional: Configure key encryption if certificate is available |
124 | | - var certPath = Environment.GetEnvironmentVariable("DATA_PROTECTION_CERT_PATH"); |
125 | | - if (!string.IsNullOrEmpty(certPath) && File.Exists(certPath)) |
126 | | - { |
127 | | - var certPassword = Environment.GetEnvironmentVariable("DATA_PROTECTION_CERT_PASSWORD"); |
128 | | -#pragma warning disable SYSLIB0057 // Type or member is obsolete, No overload for new API accepts a password. |
129 | | - var cert = new X509Certificate2(certPath, certPassword); |
130 | | -#pragma warning restore SYSLIB0057 // Type or member is obsolete |
131 | | - dataProtectionBuilder.ProtectKeysWithCertificate(cert); |
132 | | - } |
133 | | - } |
134 | | - else |
135 | | - { |
136 | | - // Development configuration |
137 | | - var keysPath = Path.Combine(builder.Environment.ContentRootPath, "keys"); |
138 | | - Directory.CreateDirectory(keysPath); |
139 | | - dataProtectionBuilder.PersistKeysToFileSystem(new DirectoryInfo(keysPath)); |
140 | | - } |
141 | | - } |
142 | 102 | } |
0 commit comments