From ee97897ff98c6eb61d6fee77d2936b6f5ac5ecea Mon Sep 17 00:00:00 2001 From: Ivar Nesje Date: Fri, 22 Nov 2024 10:40:15 +0100 Subject: [PATCH] Fix discovery document to not print `null` for bolean properties (#125) This crashes on the latest version of Microsoft.IdentityModel.Protocols.OpenIdConnect And is required for app-lib-dotnet 8.5 --- .../Authentication/DiscoveryDocument.cs | 54 ++++++++++++------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/src/Models/Authentication/DiscoveryDocument.cs b/src/Models/Authentication/DiscoveryDocument.cs index 7b582572..5f8256a6 100644 --- a/src/Models/Authentication/DiscoveryDocument.cs +++ b/src/Models/Authentication/DiscoveryDocument.cs @@ -1,3 +1,4 @@ +#nullable enable using System.Text.Json.Serialization; namespace Altinn.Platform.Authentication.Model @@ -12,120 +13,135 @@ public class DiscoveryDocument /// URL of the issuer /// [JsonPropertyName("issuer")] - public string Issuer { get; set; } + public required string Issuer { get; set; } /// /// URL of the JSON Web Key Set document. /// [JsonPropertyName("jwks_uri")] - public string JwksUri { get; set; } + public required string JwksUri { get; set; } /// /// URL of the OAuth 2.0 Authorization Endpoint. /// [JsonPropertyName("authorization_endpoint")] - public string AuthorizationEndpoint { get; set; } + public required string AuthorizationEndpoint { get; set; } /// /// URL of the OAuth 2.0 Token Endpoint. /// [JsonPropertyName("token_endpoint")] - public string TokenEndpoint { get; set; } + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? TokenEndpoint { get; set; } /// /// Url of the UserInfo Endpoint. /// [JsonPropertyName("userinfo_endpoint")] - public string UserinfoEndpoint { get; set; } + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? UserinfoEndpoint { get; set; } /// /// URL of the end session Endpoint. /// [JsonPropertyName("end_session_endpoint")] - public string EndSessionEndpoint { get; set; } + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? EndSessionEndpoint { get; set; } /// /// URL for the session check Endpoint. /// [JsonPropertyName("check_session_iframe")] - public string CheckSessionIframe { get; set; } + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? CheckSessionIframe { get; set; } /// /// URL for the revocation endpoint. /// [JsonPropertyName("revocation_endpoint")] - public string RevocationEndpoint { get; set; } + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? RevocationEndpoint { get; set; } /// /// URL for the introspection endpoint. /// [JsonPropertyName("introspection_endpoint")] - public string IntrospectionEndpoint { get; set; } + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? IntrospectionEndpoint { get; set; } /// /// Value indicating whether there is a front channel mechanism for logout. /// [JsonPropertyName("frontchannel_logout_supported")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public bool? FrontchannelLogoutSupported { get; set; } /// /// Value indicating wheter there is a front channel mechanism for session logout. /// [JsonPropertyName("frontchannel_logout_session_supported")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public bool? FrontchannelLogoutSessionSupported { get; set; } /// /// Array of supported scopes. /// [JsonPropertyName("scopes_supported")] - public string[] ScopesSupported { get; set; } + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string[]? ScopesSupported { get; set; } /// /// Array of supported claims. /// [JsonPropertyName("claims_supported")] - public string[] ClaimsSupported { get; set; } + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string[]? ClaimsSupported { get; set; } /// /// Array of supported response types. /// [JsonPropertyName("response_types_supported")] - public string[] ResponseTypesSupported { get; set; } + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string[]? ResponseTypesSupported { get; set; } /// /// Array of supported response modes. /// [JsonPropertyName("response_modes_supported")] - public string[] ResponseModesSupported { get; set; } + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string[]? ResponseModesSupported { get; set; } /// /// Array of supported grant types. /// [JsonPropertyName("grant_types_supported")] - public string[] GrantTypesSupported { get; set; } + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string[]? GrantTypesSupported { get; set; } /// /// Array of supported subject types. /// [JsonPropertyName("subject_types_supported")] - public string[] SubjectTypesSupported { get; set; } + public required string[] SubjectTypesSupported { get; set; } /// /// Array of supported signing algorithms. /// [JsonPropertyName("id_token_signing_alg_values_supported")] - public string[] IdTokenSigningAlgValuesSupported { get; set; } + public required string[] IdTokenSigningAlgValuesSupported { get; set; } /// /// Array of supported authentication methods on the token endpoint. /// [JsonPropertyName("token_endpoint_auth_methods_supported")] - public string[] TokenEndpointAuthMethodsSupported { get; set; } + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string[]? TokenEndpointAuthMethodsSupported { get; set; } /// /// Array of supported code challenge methods. /// [JsonPropertyName("code_challenge_methods_supported")] - public string[] CodeChallengeMethodsSupported { get; set; } + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string[]? CodeChallengeMethodsSupported { get; set; } } -} +} \ No newline at end of file