-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Add ClaimData for AuthenticationStateData and fix overtrimming #56878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Security.Claims; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Microsoft.AspNetCore.Components.Authorization; | ||
|
||
/// <summary> | ||
/// This is a serializable representation of a <see cref="Claim"/> object that only consists of the type and value. | ||
/// </summary> | ||
public readonly struct ClaimData | ||
{ | ||
/// <summary> | ||
/// Constructs a new instance of <see cref="ClaimData"/> from a type and value. | ||
/// </summary> | ||
/// <param name="type">The claim type.</param> | ||
/// <param name="value">The claim value</param> | ||
[JsonConstructor] | ||
public ClaimData(string type, string value) | ||
{ | ||
Type = type; | ||
Value = value; | ||
} | ||
|
||
/// <summary> | ||
/// Constructs a new instance of <see cref="ClaimData"/> from a <see cref="Claim"/> copying only the | ||
/// <see cref="Claim.Type"/> and <see cref="Claim.Value"/> into their corresponding properties. | ||
/// </summary> | ||
/// <param name="claim">The <see cref="Claim"/> to copy from.</param> | ||
public ClaimData(Claim claim) | ||
: this(claim.Type, claim.Value) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Gets the claim type of the claim. <seealso cref="ClaimTypes"/>. | ||
/// </summary> | ||
public string Type { get; } | ||
|
||
/// <summary> | ||
/// Gets the value of the claim. | ||
/// </summary> | ||
public string Value { get; } | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
#nullable enable | ||
Microsoft.AspNetCore.Components.Authorization.AuthenticationStateData | ||
Microsoft.AspNetCore.Components.Authorization.AuthenticationStateData.AuthenticationStateData() -> void | ||
Microsoft.AspNetCore.Components.Authorization.AuthenticationStateData.Claims.get -> System.Collections.Generic.IList<System.Collections.Generic.KeyValuePair<string!, string!>>! | ||
Microsoft.AspNetCore.Components.Authorization.AuthenticationStateData.Claims.get -> System.Collections.Generic.IList<Microsoft.AspNetCore.Components.Authorization.ClaimData>! | ||
Microsoft.AspNetCore.Components.Authorization.AuthenticationStateData.Claims.set -> void | ||
Microsoft.AspNetCore.Components.Authorization.AuthenticationStateData.NameClaimType.get -> string! | ||
Microsoft.AspNetCore.Components.Authorization.AuthenticationStateData.NameClaimType.set -> void | ||
Microsoft.AspNetCore.Components.Authorization.AuthenticationStateData.RoleClaimType.get -> string! | ||
Microsoft.AspNetCore.Components.Authorization.AuthenticationStateData.RoleClaimType.set -> void | ||
Microsoft.AspNetCore.Components.Authorization.ClaimData | ||
Microsoft.AspNetCore.Components.Authorization.ClaimData.ClaimData() -> void | ||
Microsoft.AspNetCore.Components.Authorization.ClaimData.ClaimData(string! type, string! value) -> void | ||
Microsoft.AspNetCore.Components.Authorization.ClaimData.ClaimData(System.Security.Claims.Claim! claim) -> void | ||
Microsoft.AspNetCore.Components.Authorization.ClaimData.Type.get -> string! | ||
Microsoft.AspNetCore.Components.Authorization.ClaimData.Value.get -> string! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/Components/test/E2ETest/Infrastructure/ServerFixtures/TrimmingServerFixture.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Reflection; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Logging.Testing; | ||
|
||
namespace Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures; | ||
|
||
public class TrimmingServerFixture<TStartup> : BasicTestAppServerSiteFixture<TStartup> where TStartup : class | ||
{ | ||
public readonly bool TestTrimmedApps = typeof(ToggleExecutionModeServerFixture<>).Assembly | ||
.GetCustomAttributes<AssemblyMetadataAttribute>() | ||
.First(m => m.Key == "Microsoft.AspNetCore.E2ETesting.TestTrimmedOrMultithreadingApps") | ||
.Value == "true"; | ||
|
||
public TrimmingServerFixture() | ||
{ | ||
if (TestTrimmedApps) | ||
{ | ||
BuildWebHostMethod = BuildPublishedWebHost; | ||
GetContentRootMethod = GetPublishedContentRoot; | ||
} | ||
} | ||
|
||
private static IHost BuildPublishedWebHost(string[] args) => | ||
Extensions.Hosting.Host.CreateDefaultBuilder(args) | ||
.ConfigureLogging((ctx, lb) => | ||
{ | ||
var sink = new TestSink(); | ||
lb.AddProvider(new TestLoggerProvider(sink)); | ||
lb.Services.AddSingleton(sink); | ||
}) | ||
.ConfigureWebHostDefaults(webHostBuilder => | ||
{ | ||
webHostBuilder.UseStartup<TStartup>(); | ||
// Avoid UseStaticAssets or we won't use the trimmed published output. | ||
}) | ||
.Build(); | ||
|
||
private static string GetPublishedContentRoot(Assembly assembly) | ||
{ | ||
var contentRoot = Path.Combine(AppContext.BaseDirectory, "trimmed-or-threading", assembly.GetName().Name); | ||
|
||
if (!Directory.Exists(contentRoot)) | ||
{ | ||
throw new DirectoryNotFoundException($"Test is configured to use trimmed outputs, but trimmed outputs were not found in {contentRoot}."); | ||
} | ||
|
||
return contentRoot; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.