diff --git a/eng/TrimmableProjects.props b/eng/TrimmableProjects.props
index a0b698bab8bc..5f86c590f41a 100644
--- a/eng/TrimmableProjects.props
+++ b/eng/TrimmableProjects.props
@@ -14,6 +14,7 @@
+
@@ -37,7 +38,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -56,6 +71,7 @@
+
diff --git a/src/Antiforgery/src/Microsoft.AspNetCore.Antiforgery.csproj b/src/Antiforgery/src/Microsoft.AspNetCore.Antiforgery.csproj
index 4723a65cecd5..38e1754535ff 100644
--- a/src/Antiforgery/src/Microsoft.AspNetCore.Antiforgery.csproj
+++ b/src/Antiforgery/src/Microsoft.AspNetCore.Antiforgery.csproj
@@ -7,7 +7,7 @@
true
aspnetcore;antiforgery
false
- enable
+ true
diff --git a/src/Middleware/Session/src/Microsoft.AspNetCore.Session.csproj b/src/Middleware/Session/src/Microsoft.AspNetCore.Session.csproj
index e051bef8b032..8d1d60b659eb 100644
--- a/src/Middleware/Session/src/Microsoft.AspNetCore.Session.csproj
+++ b/src/Middleware/Session/src/Microsoft.AspNetCore.Session.csproj
@@ -8,7 +8,7 @@
true
aspnetcore;session;sessionstate
false
- enable
+ true
diff --git a/src/Security/Authentication/Certificate/src/Microsoft.AspNetCore.Authentication.Certificate.csproj b/src/Security/Authentication/Certificate/src/Microsoft.AspNetCore.Authentication.Certificate.csproj
index b56a0db9df76..9b4c99466740 100644
--- a/src/Security/Authentication/Certificate/src/Microsoft.AspNetCore.Authentication.Certificate.csproj
+++ b/src/Security/Authentication/Certificate/src/Microsoft.AspNetCore.Authentication.Certificate.csproj
@@ -6,7 +6,7 @@
$(DefineConstants);SECURITY
true
aspnetcore;authentication;security;x509;certificate
- enable
+ true
diff --git a/src/Security/Authentication/Cookies/src/Microsoft.AspNetCore.Authentication.Cookies.csproj b/src/Security/Authentication/Cookies/src/Microsoft.AspNetCore.Authentication.Cookies.csproj
index cc235c07f497..6a3843e97683 100644
--- a/src/Security/Authentication/Cookies/src/Microsoft.AspNetCore.Authentication.Cookies.csproj
+++ b/src/Security/Authentication/Cookies/src/Microsoft.AspNetCore.Authentication.Cookies.csproj
@@ -8,7 +8,7 @@
true
aspnetcore;authentication;security
false
- enable
+ true
diff --git a/src/Security/Authentication/Core/src/AuthenticationBuilder.cs b/src/Security/Authentication/Core/src/AuthenticationBuilder.cs
index 49d8f32fddbc..9a2c7deea1fe 100644
--- a/src/Security/Authentication/Core/src/AuthenticationBuilder.cs
+++ b/src/Security/Authentication/Core/src/AuthenticationBuilder.cs
@@ -29,11 +29,12 @@ public AuthenticationBuilder(IServiceCollection services)
where TOptions : AuthenticationSchemeOptions, new()
where THandler : class, IAuthenticationHandler
{
+ var state = new AddSchemeHelperState(typeof(THandler));
Services.Configure(o =>
{
o.AddScheme(authenticationScheme, scheme =>
{
- scheme.HandlerType = typeof(THandler);
+ scheme.HandlerType = state.HandlerType;
scheme.DisplayName = displayName;
});
});
@@ -50,6 +51,18 @@ public AuthenticationBuilder(IServiceCollection services)
return this;
}
+ // Workaround for linker bug: https://github.com/dotnet/linker/issues/1981
+ private readonly struct AddSchemeHelperState
+ {
+ public AddSchemeHelperState([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type handlerType)
+ {
+ HandlerType = handlerType;
+ }
+
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
+ public Type HandlerType { get; }
+ }
+
///
/// Adds a which can be used by .
///
diff --git a/src/Security/Authentication/Core/src/Microsoft.AspNetCore.Authentication.csproj b/src/Security/Authentication/Core/src/Microsoft.AspNetCore.Authentication.csproj
index 4598a5b8660c..32546d575cb1 100644
--- a/src/Security/Authentication/Core/src/Microsoft.AspNetCore.Authentication.csproj
+++ b/src/Security/Authentication/Core/src/Microsoft.AspNetCore.Authentication.csproj
@@ -7,7 +7,7 @@
true
aspnetcore;authentication;security
false
- enable
+ true
diff --git a/src/Security/Authentication/Facebook/src/Microsoft.AspNetCore.Authentication.Facebook.csproj b/src/Security/Authentication/Facebook/src/Microsoft.AspNetCore.Authentication.Facebook.csproj
index ece1e5408e9c..729c381798a1 100644
--- a/src/Security/Authentication/Facebook/src/Microsoft.AspNetCore.Authentication.Facebook.csproj
+++ b/src/Security/Authentication/Facebook/src/Microsoft.AspNetCore.Authentication.Facebook.csproj
@@ -5,7 +5,7 @@
$(DefaultNetCoreTargetFramework)
true
aspnetcore;authentication;security
- enable
+ true
diff --git a/src/Security/Authentication/Google/src/Microsoft.AspNetCore.Authentication.Google.csproj b/src/Security/Authentication/Google/src/Microsoft.AspNetCore.Authentication.Google.csproj
index 04e062a02be9..8180fa0c1172 100644
--- a/src/Security/Authentication/Google/src/Microsoft.AspNetCore.Authentication.Google.csproj
+++ b/src/Security/Authentication/Google/src/Microsoft.AspNetCore.Authentication.Google.csproj
@@ -5,7 +5,7 @@
$(DefaultNetCoreTargetFramework)
true
aspnetcore;authentication;security
- enable
+ true
diff --git a/src/Security/Authentication/JwtBearer/src/Microsoft.AspNetCore.Authentication.JwtBearer.csproj b/src/Security/Authentication/JwtBearer/src/Microsoft.AspNetCore.Authentication.JwtBearer.csproj
index b54ae6e24e72..fedcb161248a 100644
--- a/src/Security/Authentication/JwtBearer/src/Microsoft.AspNetCore.Authentication.JwtBearer.csproj
+++ b/src/Security/Authentication/JwtBearer/src/Microsoft.AspNetCore.Authentication.JwtBearer.csproj
@@ -5,7 +5,7 @@
$(DefaultNetCoreTargetFramework)
true
aspnetcore;authentication;security
- enable
+ true
diff --git a/src/Security/Authentication/MicrosoftAccount/src/Microsoft.AspNetCore.Authentication.MicrosoftAccount.csproj b/src/Security/Authentication/MicrosoftAccount/src/Microsoft.AspNetCore.Authentication.MicrosoftAccount.csproj
index ff9cc3f3c7de..b86749748334 100644
--- a/src/Security/Authentication/MicrosoftAccount/src/Microsoft.AspNetCore.Authentication.MicrosoftAccount.csproj
+++ b/src/Security/Authentication/MicrosoftAccount/src/Microsoft.AspNetCore.Authentication.MicrosoftAccount.csproj
@@ -5,7 +5,7 @@
$(DefaultNetCoreTargetFramework)
true
aspnetcore;authentication;security
- enable
+ true
diff --git a/src/Security/Authentication/Negotiate/src/Internal/INegotiateStateFactory.cs b/src/Security/Authentication/Negotiate/src/Internal/INegotiateStateFactory.cs
index 1907e9098c67..997ca0b06ebe 100644
--- a/src/Security/Authentication/Negotiate/src/Internal/INegotiateStateFactory.cs
+++ b/src/Security/Authentication/Negotiate/src/Internal/INegotiateStateFactory.cs
@@ -1,10 +1,13 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+using System.Diagnostics.CodeAnalysis;
+
namespace Microsoft.AspNetCore.Authentication.Negotiate;
// For testing
internal interface INegotiateStateFactory
{
+ [RequiresUnreferencedCode("Negotiate authentication uses types that cannot be statically analyzed.")]
INegotiateState CreateInstance();
}
diff --git a/src/Security/Authentication/Negotiate/src/Internal/ReflectedNegotiateState.cs b/src/Security/Authentication/Negotiate/src/Internal/ReflectedNegotiateState.cs
index f07d40f495d2..2ed30658504a 100644
--- a/src/Security/Authentication/Negotiate/src/Internal/ReflectedNegotiateState.cs
+++ b/src/Security/Authentication/Negotiate/src/Internal/ReflectedNegotiateState.cs
@@ -3,6 +3,7 @@
#pragma warning disable CA1810 // Initialize all static fields inline.
+using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Net;
using System.Reflection;
@@ -12,6 +13,7 @@
namespace Microsoft.AspNetCore.Authentication.Negotiate;
+[RequiresUnreferencedCode("Negotiate authentication uses types that cannot be statically analyzed.")]
internal sealed class ReflectedNegotiateState : INegotiateState
{
// https://www.gnu.org/software/gss/reference/gss.pdf
diff --git a/src/Security/Authentication/Negotiate/src/Internal/ReflectedNegotiateStateFactory.cs b/src/Security/Authentication/Negotiate/src/Internal/ReflectedNegotiateStateFactory.cs
index ac732e67112a..4a418b07f91b 100644
--- a/src/Security/Authentication/Negotiate/src/Internal/ReflectedNegotiateStateFactory.cs
+++ b/src/Security/Authentication/Negotiate/src/Internal/ReflectedNegotiateStateFactory.cs
@@ -1,10 +1,13 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+using System.Diagnostics.CodeAnalysis;
+
namespace Microsoft.AspNetCore.Authentication.Negotiate;
internal sealed class ReflectedNegotiateStateFactory : INegotiateStateFactory
{
+ [RequiresUnreferencedCode("Negotiate authentication uses types that cannot be statically analyzed.")]
public INegotiateState CreateInstance()
{
return new ReflectedNegotiateState();
diff --git a/src/Security/Authentication/Negotiate/src/Microsoft.AspNetCore.Authentication.Negotiate.csproj b/src/Security/Authentication/Negotiate/src/Microsoft.AspNetCore.Authentication.Negotiate.csproj
index fe9c418c7e74..edfcac2a4d82 100644
--- a/src/Security/Authentication/Negotiate/src/Microsoft.AspNetCore.Authentication.Negotiate.csproj
+++ b/src/Security/Authentication/Negotiate/src/Microsoft.AspNetCore.Authentication.Negotiate.csproj
@@ -5,7 +5,7 @@
$(DefaultNetCoreTargetFramework)
true
aspnetcore;authentication;security
- enable
+ true
diff --git a/src/Security/Authentication/Negotiate/src/NegotiateExtensions.cs b/src/Security/Authentication/Negotiate/src/NegotiateExtensions.cs
index c71824f54f8c..a2d03767ec5b 100644
--- a/src/Security/Authentication/Negotiate/src/NegotiateExtensions.cs
+++ b/src/Security/Authentication/Negotiate/src/NegotiateExtensions.cs
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+using System.Diagnostics.CodeAnalysis;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Negotiate;
using Microsoft.AspNetCore.Authentication.Negotiate.Internal;
@@ -24,6 +25,7 @@ public static class NegotiateExtensions
///
/// The .
/// The original builder.
+ [RequiresUnreferencedCode("Negotiate authentication uses types that cannot be statically analyzed.")]
public static AuthenticationBuilder AddNegotiate(this AuthenticationBuilder builder)
=> builder.AddNegotiate(NegotiateDefaults.AuthenticationScheme, _ => { });
@@ -37,6 +39,7 @@ public static AuthenticationBuilder AddNegotiate(this AuthenticationBuilder buil
/// The .
/// Allows for configuring the authentication handler.
/// The original builder.
+ [RequiresUnreferencedCode("Negotiate authentication uses types that cannot be statically analyzed.")]
public static AuthenticationBuilder AddNegotiate(this AuthenticationBuilder builder, Action configureOptions)
=> builder.AddNegotiate(NegotiateDefaults.AuthenticationScheme, configureOptions);
@@ -51,6 +54,7 @@ public static AuthenticationBuilder AddNegotiate(this AuthenticationBuilder buil
/// The scheme name used to identify the authentication handler internally.
/// Allows for configuring the authentication handler.
/// The original builder.
+ [RequiresUnreferencedCode("Negotiate authentication uses types that cannot be statically analyzed.")]
public static AuthenticationBuilder AddNegotiate(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions)
=> builder.AddNegotiate(authenticationScheme, displayName: null, configureOptions: configureOptions);
@@ -66,6 +70,7 @@ public static AuthenticationBuilder AddNegotiate(this AuthenticationBuilder buil
/// The name displayed to users when selecting an authentication handler. The default is null to prevent this from displaying.
/// Allows for configuring the authentication handler.
/// The original builder.
+ [RequiresUnreferencedCode("Negotiate authentication uses types that cannot be statically analyzed.")]
public static AuthenticationBuilder AddNegotiate(this AuthenticationBuilder builder, string authenticationScheme, string? displayName, Action configureOptions)
{
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton, PostConfigureNegotiateOptions>());
diff --git a/src/Security/Authentication/Negotiate/src/NegotiateHandler.cs b/src/Security/Authentication/Negotiate/src/NegotiateHandler.cs
index 12c7395f6663..f12b1ae7b1ea 100644
--- a/src/Security/Authentication/Negotiate/src/NegotiateHandler.cs
+++ b/src/Security/Authentication/Negotiate/src/NegotiateHandler.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Security.Claims;
using System.Security.Principal;
@@ -18,6 +19,7 @@ namespace Microsoft.AspNetCore.Authentication.Negotiate;
///
/// Authenticates requests using Negotiate, Kerberos, or NTLM.
///
+[RequiresUnreferencedCode("Negotiate authentication uses types that cannot be statically analyzed.")]
public class NegotiateHandler : AuthenticationHandler, IAuthenticationRequestHandler
{
private const string AuthPersistenceKey = nameof(AuthPersistence);
diff --git a/src/Security/Authentication/OAuth/src/Microsoft.AspNetCore.Authentication.OAuth.csproj b/src/Security/Authentication/OAuth/src/Microsoft.AspNetCore.Authentication.OAuth.csproj
index c3e2e400e43c..204e60ed0db3 100644
--- a/src/Security/Authentication/OAuth/src/Microsoft.AspNetCore.Authentication.OAuth.csproj
+++ b/src/Security/Authentication/OAuth/src/Microsoft.AspNetCore.Authentication.OAuth.csproj
@@ -7,7 +7,7 @@
true
aspnetcore;authentication;security
false
- enable
+ true
diff --git a/src/Security/Authentication/OpenIdConnect/src/Microsoft.AspNetCore.Authentication.OpenIdConnect.csproj b/src/Security/Authentication/OpenIdConnect/src/Microsoft.AspNetCore.Authentication.OpenIdConnect.csproj
index b51566495afe..18f237b0cbfd 100644
--- a/src/Security/Authentication/OpenIdConnect/src/Microsoft.AspNetCore.Authentication.OpenIdConnect.csproj
+++ b/src/Security/Authentication/OpenIdConnect/src/Microsoft.AspNetCore.Authentication.OpenIdConnect.csproj
@@ -5,7 +5,7 @@
$(DefaultNetCoreTargetFramework)
true
aspnetcore;authentication;security
- enable
+ true
diff --git a/src/Security/Authentication/Twitter/src/Microsoft.AspNetCore.Authentication.Twitter.csproj b/src/Security/Authentication/Twitter/src/Microsoft.AspNetCore.Authentication.Twitter.csproj
index 194713d2ce3a..c868859675fe 100644
--- a/src/Security/Authentication/Twitter/src/Microsoft.AspNetCore.Authentication.Twitter.csproj
+++ b/src/Security/Authentication/Twitter/src/Microsoft.AspNetCore.Authentication.Twitter.csproj
@@ -5,7 +5,7 @@
$(DefaultNetCoreTargetFramework)
true
aspnetcore;authentication;security
- enable
+ true
diff --git a/src/Security/Authentication/Twitter/src/TwitterHandler.cs b/src/Security/Authentication/Twitter/src/TwitterHandler.cs
index 0dd53355624a..a65d9ba0cf43 100644
--- a/src/Security/Authentication/Twitter/src/TwitterHandler.cs
+++ b/src/Security/Authentication/Twitter/src/TwitterHandler.cs
@@ -8,6 +8,7 @@
using System.Text;
using System.Text.Encodings.Web;
using System.Text.Json;
+using System.Text.Json.Serialization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.Extensions.Logging;
@@ -19,13 +20,8 @@ namespace Microsoft.AspNetCore.Authentication.Twitter;
///
/// Authentication handler for Twitter's OAuth based authentication.
///
-public class TwitterHandler : RemoteAuthenticationHandler
+public partial class TwitterHandler : RemoteAuthenticationHandler
{
- private static readonly JsonSerializerOptions ErrorSerializerOptions = new JsonSerializerOptions
- {
- PropertyNameCaseInsensitive = true
- };
-
private HttpClient Backchannel => Options.Backchannel;
///
@@ -361,7 +357,7 @@ private async Task EnsureTwitterRequestSuccess(HttpResponseMessage response)
{
// Failure, attempt to parse Twitters error message
var errorContentStream = await response.Content.ReadAsStreamAsync(Context.RequestAborted);
- errorResponse = await JsonSerializer.DeserializeAsync(errorContentStream, ErrorSerializerOptions);
+ errorResponse = await JsonSerializer.DeserializeAsync(errorContentStream, TwitterJsonContext.DefaultWithOptions.TwitterErrorResponse);
}
catch
{
@@ -390,4 +386,13 @@ private async Task EnsureTwitterRequestSuccess(HttpResponseMessage response)
throw new InvalidOperationException(errorMessageStringBuilder.ToString());
}
+
+ [JsonSerializable(typeof(TwitterErrorResponse))]
+ internal sealed partial class TwitterJsonContext : JsonSerializerContext
+ {
+ public static readonly TwitterJsonContext DefaultWithOptions = new TwitterJsonContext(new JsonSerializerOptions
+ {
+ PropertyNameCaseInsensitive = true
+ });
+ }
}
diff --git a/src/Security/Authentication/WsFederation/src/Microsoft.AspNetCore.Authentication.WsFederation.csproj b/src/Security/Authentication/WsFederation/src/Microsoft.AspNetCore.Authentication.WsFederation.csproj
index f14899cafe6c..b68b19f727b7 100644
--- a/src/Security/Authentication/WsFederation/src/Microsoft.AspNetCore.Authentication.WsFederation.csproj
+++ b/src/Security/Authentication/WsFederation/src/Microsoft.AspNetCore.Authentication.WsFederation.csproj
@@ -5,7 +5,7 @@
$(DefaultNetCoreTargetFramework)
true
aspnetcore;authentication;security
- enable
+ true
diff --git a/src/Security/Authorization/Policy/src/Microsoft.AspNetCore.Authorization.Policy.csproj b/src/Security/Authorization/Policy/src/Microsoft.AspNetCore.Authorization.Policy.csproj
index 088318e51324..443d62ff4c5f 100644
--- a/src/Security/Authorization/Policy/src/Microsoft.AspNetCore.Authorization.Policy.csproj
+++ b/src/Security/Authorization/Policy/src/Microsoft.AspNetCore.Authorization.Policy.csproj
@@ -7,7 +7,7 @@
true
aspnetcore;authorization
false
- enable
+ true
diff --git a/src/Security/CookiePolicy/src/Microsoft.AspNetCore.CookiePolicy.csproj b/src/Security/CookiePolicy/src/Microsoft.AspNetCore.CookiePolicy.csproj
index b0c5252e805e..aab3dc37f5f2 100644
--- a/src/Security/CookiePolicy/src/Microsoft.AspNetCore.CookiePolicy.csproj
+++ b/src/Security/CookiePolicy/src/Microsoft.AspNetCore.CookiePolicy.csproj
@@ -7,7 +7,7 @@
true
aspnetcore
false
- enable
+ true
diff --git a/src/Tools/Tools.slnf b/src/Tools/Tools.slnf
index c90d6923b4e4..8527dde99dcc 100644
--- a/src/Tools/Tools.slnf
+++ b/src/Tools/Tools.slnf
@@ -63,7 +63,21 @@
"src\\Middleware\\StaticFiles\\src\\Microsoft.AspNetCore.StaticFiles.csproj",
"src\\Middleware\\WebSockets\\src\\Microsoft.AspNetCore.WebSockets.csproj",
"src\\ObjectPool\\src\\Microsoft.Extensions.ObjectPool.csproj",
+ "src\\Security\\Authentication\\Certificate\\src\\Microsoft.AspNetCore.Authentication.Certificate.csproj",
+ "src\\Security\\Authentication\\Cookies\\src\\Microsoft.AspNetCore.Authentication.Cookies.csproj",
+ "src\\Security\\Authentication\\Core\\src\\Microsoft.AspNetCore.Authentication.csproj",
+ "src\\Security\\Authentication\\Facebook\\src\\Microsoft.AspNetCore.Authentication.Facebook.csproj",
+ "src\\Security\\Authentication\\Google\\src\\Microsoft.AspNetCore.Authentication.Google.csproj",
+ "src\\Security\\Authentication\\JwtBearer\\src\\Microsoft.AspNetCore.Authentication.JwtBearer.csproj",
+ "src\\Security\\Authentication\\MicrosoftAccount\\src\\Microsoft.AspNetCore.Authentication.MicrosoftAccount.csproj",
+ "src\\Security\\Authentication\\Negotiate\\src\\Microsoft.AspNetCore.Authentication.Negotiate.csproj",
+ "src\\Security\\Authentication\\OAuth\\src\\Microsoft.AspNetCore.Authentication.OAuth.csproj",
+ "src\\Security\\Authentication\\OpenIdConnect\\src\\Microsoft.AspNetCore.Authentication.OpenIdConnect.csproj",
+ "src\\Security\\Authentication\\Twitter\\src\\Microsoft.AspNetCore.Authentication.Twitter.csproj",
+ "src\\Security\\Authentication\\WsFederation\\src\\Microsoft.AspNetCore.Authentication.WsFederation.csproj",
"src\\Security\\Authorization\\Core\\src\\Microsoft.AspNetCore.Authorization.csproj",
+ "src\\Security\\Authorization\\Policy\\src\\Microsoft.AspNetCore.Authorization.Policy.csproj",
+ "src\\Security\\CookiePolicy\\src\\Microsoft.AspNetCore.CookiePolicy.csproj",
"src\\Servers\\Connections.Abstractions\\src\\Microsoft.AspNetCore.Connections.Abstractions.csproj",
"src\\Servers\\HttpSys\\src\\Microsoft.AspNetCore.Server.HttpSys.csproj",
"src\\Servers\\IIS\\IISIntegration\\src\\Microsoft.AspNetCore.Server.IISIntegration.csproj",