From 7f9a978a8618ff5e3a05d32fb0d5e372e790d1db Mon Sep 17 00:00:00 2001 From: jacalvar Date: Fri, 11 Nov 2022 11:52:57 +0100 Subject: Fix linker issues --- .../src/ILLink.Descriptors.xml | 5 ++ ...re.Components.WebAssembly.Authentication.csproj | 4 ++ .../src/Models/InteractiveRequestOptions.cs | 59 ++++++++++++++-------- .../src/RemoteAuthenticatorViewCore.Log.cs | 3 ++ .../src/RemoteAuthenticatorViewCore.cs | 1 + 5 files changed, 52 insertions(+), 20 deletions(-) create mode 100644 src/Components/WebAssembly/WebAssembly.Authentication/src/ILLink.Descriptors.xml diff --git a/src/Components/WebAssembly/WebAssembly.Authentication/src/ILLink.Descriptors.xml b/src/Components/WebAssembly/WebAssembly.Authentication/src/ILLink.Descriptors.xml new file mode 100644 index 0000000000..a1d22402e9 --- /dev/null +++ b/src/Components/WebAssembly/WebAssembly.Authentication/src/ILLink.Descriptors.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/Components/WebAssembly/WebAssembly.Authentication/src/Microsoft.AspNetCore.Components.WebAssembly.Authentication.csproj b/src/Components/WebAssembly/WebAssembly.Authentication/src/Microsoft.AspNetCore.Components.WebAssembly.Authentication.csproj index 345236f694..c9bb1d3009 100644 --- a/src/Components/WebAssembly/WebAssembly.Authentication/src/Microsoft.AspNetCore.Components.WebAssembly.Authentication.csproj +++ b/src/Components/WebAssembly/WebAssembly.Authentication/src/Microsoft.AspNetCore.Components.WebAssembly.Authentication.csproj @@ -40,6 +40,10 @@ + + + ILLink.Descriptors.xml + diff --git a/src/Components/WebAssembly/WebAssembly.Authentication/src/Models/InteractiveRequestOptions.cs b/src/Components/WebAssembly/WebAssembly.Authentication/src/Models/InteractiveRequestOptions.cs index 870b42e3db..56844d476e 100644 --- a/src/Components/WebAssembly/WebAssembly.Authentication/src/Models/InteractiveRequestOptions.cs +++ b/src/Components/WebAssembly/WebAssembly.Authentication/src/Models/InteractiveRequestOptions.cs @@ -14,6 +14,12 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication; [JsonConverter(typeof(Converter))] public sealed class InteractiveRequestOptions { + private static readonly JsonSerializerOptions SerializerOptions = new JsonSerializerOptions + { + MaxDepth = 32, + PropertyNameCaseInsensitive = true, + }; + /// /// Gets the request type. /// @@ -86,17 +92,29 @@ public sealed class InteractiveRequestOptions static TValue Deserialize(JsonElement element) => element.Deserialize(); } - internal string ToState() => JsonSerializer.Serialize(this, InteractiveRequestOptionsSerializerContext.Default.InteractiveRequestOptions); - - internal static InteractiveRequestOptions FromState(string state) => JsonSerializer.Deserialize( + [UnconditionalSuppressMessage( + "Trimming", + "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", + Justification = "This method serializes InteractiveRequestOptions which has an 'AdditionalRequestParameters' that might contain user defined types but that have already been annotated by 'TryAddAdditionalParameter'.")] + internal string ToState() => JsonSerializer.Serialize(this, SerializerOptions); + + [UnconditionalSuppressMessage( + "Trimming", + "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", + Justification = "This method deserializes InteractiveRequestOptions which has an 'AdditionalRequestParameters' that might contain user defined types but that have already been annotated by 'TryAddAdditionalParameter'.")] + internal static InteractiveRequestOptions FromState(string state) => JsonSerializer.Deserialize( state, - InteractiveRequestOptionsSerializerContext.Default.InteractiveRequestOptions); + SerializerOptions); internal class Converter : JsonConverter { + [UnconditionalSuppressMessage( + "Trimming", + "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", + Justification = "This converter reads 'AdditionalRequestParameters' that might contain user defined types but that have already been annotated by 'TryAddAdditionalParameter'.")] public override InteractiveRequestOptions Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - var requestOptions = JsonSerializer.Deserialize(ref reader, InteractiveRequestOptionsSerializerContext.Default.OptionsRecord); + var requestOptions = JsonSerializer.Deserialize(ref reader, options); return new InteractiveRequestOptions { @@ -107,26 +125,27 @@ public sealed class InteractiveRequestOptions }; } + [UnconditionalSuppressMessage( + "Trimming", + "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", + Justification = "This converter writes 'AdditionalRequestParameters' that might contain user defined types but that have already been annotated by 'TryAddAdditionalParameter'.")] public override void Write(Utf8JsonWriter writer, InteractiveRequestOptions value, JsonSerializerOptions options) { JsonSerializer.Serialize( writer, - new OptionsRecord(value.ReturnUrl, value.Scopes, value.Interaction, value.AdditionalRequestParameters), - InteractiveRequestOptionsSerializerContext.Default.OptionsRecord); + new InteractiveOptions { ReturnUrl = value.ReturnUrl, Scopes = value.Scopes, Interaction = value.Interaction, AdditionalRequestParameters = value.AdditionalRequestParameters }, + options); } - internal record struct OptionsRecord( - [property: JsonInclude] string ReturnUrl, - [property: JsonInclude] IEnumerable Scopes, - [property: JsonInclude] InteractionType Interaction, - [property: JsonInclude] Dictionary AdditionalRequestParameters); - } -} + public struct InteractiveOptions + { + public string ReturnUrl { get; set; } -[JsonSourceGenerationOptions(PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase, WriteIndented = false)] -[JsonSerializable(typeof(InteractiveRequestOptions))] -[JsonSerializable(typeof(InteractiveRequestOptions.Converter.OptionsRecord))] -[JsonSerializable(typeof(JsonElement))] -internal partial class InteractiveRequestOptionsSerializerContext : JsonSerializerContext -{ + public IEnumerable Scopes { get; set; } + + public InteractionType Interaction { get; set; } + + public Dictionary AdditionalRequestParameters { get; set; } + } + } } diff --git a/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticatorViewCore.Log.cs b/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticatorViewCore.Log.cs index 2ff49351c5..a5ba57a5f2 100644 --- a/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticatorViewCore.Log.cs +++ b/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticatorViewCore.Log.cs @@ -53,5 +53,8 @@ public partial class RemoteAuthenticatorViewCore where TAu [LoggerMessage(15, LogLevel.Debug, "Logout redirect completed successfully.", EventName = nameof(LogoutRedirectCompletedSuccessfully))] public static partial void LogoutRedirectCompletedSuccessfully(ILogger logger); + + [LoggerMessage(16, LogLevel.Debug, "Login request '{Request}'.", EventName = nameof(LoginRequest))] + public static partial void LoginRequest(ILogger logger, string request); } } diff --git a/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticatorViewCore.cs b/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticatorViewCore.cs index 1f2d5788e8..9273981076 100644 --- a/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticatorViewCore.cs +++ b/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticatorViewCore.cs @@ -210,6 +210,7 @@ public partial class RemoteAuthenticatorViewCore<[DynamicallyAccessedMembers(Jso private async Task ProcessLogIn(string returnUrl) { + Log.LoginRequest(Logger, Navigation.HistoryEntryState); AuthenticationState.ReturnUrl = returnUrl; var interactiveRequest = GetCachedNavigationState(); var result = await AuthenticationService.SignInAsync(new RemoteAuthenticationContext -- cgit v1.2.3