Skip to content

Commit

Permalink
Merge in 'release/7.0' changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dotnet-bot committed Nov 14, 2022
2 parents 14443b6 + 4fcc0f0 commit 1c11d81
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<linker>
<assembly fullname="Microsoft.AspNetCore.Components.WebAssembly.Authentication">
<type fullname="Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationContext`1" preserve="all" />
</assembly>
</linker>
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@

<Content Remove="$(YarnWorkingDir)**" />
<None Include="$(YarnWorkingDir)*" Exclude="$(YarnWorkingDir)node_modules\**" />

<EmbeddedResource Include="ILLink.Descriptors.xml">
<LogicalName>ILLink.Descriptors.xml</LogicalName>
</EmbeddedResource>

<UpToDateCheckInput Include="@(YarnInputs)" Set="StaticWebassets" />
<UpToDateCheckOutput Include="@(YarnOutputs)" Set="StaticWebassets" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

/// <summary>
/// Gets the request type.
/// </summary>
Expand Down Expand Up @@ -86,17 +92,29 @@ public bool TryRemoveAdditionalParameter(string name)
static TValue Deserialize(JsonElement element) => element.Deserialize<TValue>();
}

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<InteractiveRequestOptions>(
state,
InteractiveRequestOptionsSerializerContext.Default.InteractiveRequestOptions);
SerializerOptions);

internal class Converter : JsonConverter<InteractiveRequestOptions>
{
[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<InteractiveOptions>(ref reader, options);

return new InteractiveRequestOptions
{
Expand All @@ -107,26 +125,27 @@ public override InteractiveRequestOptions Read(ref Utf8JsonReader reader, Type t
};
}

[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<string> Scopes,
[property: JsonInclude] InteractionType Interaction,
[property: JsonInclude] Dictionary<string, object> 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<string> Scopes { get; set; }

public InteractionType Interaction { get; set; }

public Dictionary<string, object> AdditionalRequestParameters { get; set; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,8 @@ private static partial class Log

[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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ protected override async Task OnParametersSetAsync()

private async Task ProcessLogIn(string returnUrl)
{
Log.LoginRequest(Logger, Navigation.HistoryEntryState);
AuthenticationState.ReturnUrl = returnUrl;
var interactiveRequest = GetCachedNavigationState();
var result = await AuthenticationService.SignInAsync(new RemoteAuthenticationContext<TAuthenticationState>
Expand Down

0 comments on commit 1c11d81

Please sign in to comment.