| | | 1 | | namespace ArturRios.Heimdall.WebApi.Security; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Settings for UC-25's Google ID token verification. Decides, at start-up, which |
| | | 5 | | /// <see cref="ArturRios.Heimdall.Command.Services.IGoogleIdTokenVerifier" /> the API runs |
| | | 6 | | /// with — the same arrangement <c>EmailDeliveryOptions</c> uses to choose between real and logged |
| | | 7 | | /// email delivery. |
| | | 8 | | /// </summary> |
| | | 9 | | public class GoogleSignInOptions |
| | | 10 | | { |
| | | 11 | | /// <summary> |
| | | 12 | | /// Comma-separated OAuth client IDs accepted as the ID token's audience (NFR-13). Google |
| | | 13 | | /// issues one token per client, so a deployment serving several front-ends lists them all. |
| | | 14 | | /// </summary> |
| | | 15 | | public const string ClientIdsVariable = "HEIMDALL_GOOGLE_CLIENT_IDS"; |
| | | 16 | | |
| | | 17 | | /// <summary> |
| | | 18 | | /// Signing secret for locally minted ID tokens, used **only** by the functional test suite — |
| | | 19 | | /// see <see cref="LocalGoogleIdTokenVerifier" /> for why it exists and what stops it reaching |
| | | 20 | | /// production. Unset everywhere except <c>PostgresFixture</c>. |
| | | 21 | | /// </summary> |
| | | 22 | | public const string TestSigningSecretVariable = "HEIMDALL_GOOGLE_TEST_SIGNING_SECRET"; |
| | | 23 | | |
| | | 24 | | /// <summary>The accepted audiences. Empty when the deployment has no Google client configured.</summary> |
| | 1824 | 25 | | public IReadOnlyList<string> ClientIds { get; init; } = []; |
| | | 26 | | |
| | | 27 | | /// <summary>The test signing secret, or empty — which is the normal case.</summary> |
| | 2765 | 28 | | public string TestSigningSecret { get; init; } = string.Empty; |
| | | 29 | | |
| | | 30 | | /// <summary>Whether a real Google client is configured, so tokens can be verified against Google.</summary> |
| | 0 | 31 | | public bool GoogleConfigured => ClientIds.Count > 0; |
| | | 32 | | |
| | | 33 | | /// <summary>Whether the locally signed tokens of the functional suite are in play.</summary> |
| | 899 | 34 | | public bool TestSigningConfigured => !string.IsNullOrWhiteSpace(TestSigningSecret); |
| | | 35 | | |
| | 899 | 36 | | public static GoogleSignInOptions FromEnvironment() => new() |
| | 899 | 37 | | { |
| | 899 | 38 | | ClientIds = (Environment.GetEnvironmentVariable(ClientIdsVariable) ?? string.Empty) |
| | 899 | 39 | | .Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries), |
| | 899 | 40 | | TestSigningSecret = |
| | 899 | 41 | | Environment.GetEnvironmentVariable(TestSigningSecretVariable) ?? string.Empty |
| | 899 | 42 | | }; |
| | | 43 | | } |