| | | 1 | | namespace Elsa.ExternalAuthentication.Services; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Centralizes removal of values that must never leave the external-authentication trust boundary. |
| | | 5 | | /// </summary> |
| | | 6 | | public static class ExternalAuthenticationRedactor |
| | | 7 | | { |
| | | 8 | | public const string RedactedValue = "[REDACTED]"; |
| | | 9 | | |
| | 2 | 10 | | public static string RedactSecret(string? secret) => RedactedValue; |
| | | 11 | | |
| | 2 | 12 | | public static string RedactToken(string? token) => RedactedValue; |
| | | 13 | | |
| | 2 | 14 | | public static string RedactProviderResponseBody(string? responseBody) => RedactedValue; |
| | | 15 | | |
| | | 16 | | public static IReadOnlyDictionary<string, IReadOnlyCollection<string>> RedactRawClaims(IReadOnlyDictionary<string, I |
| | | 17 | | { |
| | 2 | 18 | | return new Dictionary<string, IReadOnlyCollection<string>>(StringComparer.Ordinal); |
| | | 19 | | } |
| | | 20 | | |
| | | 21 | | public static IReadOnlyDictionary<string, IReadOnlyCollection<string>> RedactProjectedClaims( |
| | | 22 | | IReadOnlyDictionary<string, IReadOnlyCollection<string>> claims, |
| | | 23 | | IReadOnlySet<string> redactedClaimTypes) |
| | | 24 | | { |
| | 2 | 25 | | ArgumentNullException.ThrowIfNull(claims); |
| | 2 | 26 | | ArgumentNullException.ThrowIfNull(redactedClaimTypes); |
| | | 27 | | |
| | 2 | 28 | | var redactedClaims = new Dictionary<string, IReadOnlyCollection<string>>(claims.Count, StringComparer.Ordinal); |
| | 12 | 29 | | foreach (var (claimType, values) in claims) |
| | 4 | 30 | | redactedClaims[claimType] = redactedClaimTypes.Contains(claimType) ? [RedactedValue] : values.ToArray(); |
| | | 31 | | |
| | 2 | 32 | | return redactedClaims; |
| | | 33 | | } |
| | | 34 | | } |