Make authentication linker friendly (#24708)
* Make authentication linker friendly - Preserve constructors wherever open generics or type arguments exist
This commit is contained in:
parent
927ddab349
commit
0e592df3ec
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
|
|
@ -54,7 +55,7 @@ namespace Microsoft.AspNetCore.Authentication
|
|||
/// <typeparam name="THandler">The <see cref="IAuthenticationHandler"/> responsible for the scheme.</typeparam>
|
||||
/// <param name="name">The name of the scheme being added.</param>
|
||||
/// <param name="displayName">The display name for the scheme.</param>
|
||||
public void AddScheme<THandler>(string name, string displayName) where THandler : IAuthenticationHandler
|
||||
public void AddScheme<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]THandler>(string name, string displayName) where THandler : IAuthenticationHandler
|
||||
=> AddScheme(name, b =>
|
||||
{
|
||||
b.DisplayName = displayName;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Microsoft.AspNetCore.Authentication
|
||||
{
|
||||
|
|
@ -17,7 +18,7 @@ namespace Microsoft.AspNetCore.Authentication
|
|||
/// <param name="name">The name for the authentication scheme.</param>
|
||||
/// <param name="displayName">The display name for the authentication scheme.</param>
|
||||
/// <param name="handlerType">The <see cref="IAuthenticationHandler"/> type that handles this scheme.</param>
|
||||
public AuthenticationScheme(string name, string? displayName, Type handlerType)
|
||||
public AuthenticationScheme(string name, string? displayName, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type handlerType)
|
||||
{
|
||||
if (name == null)
|
||||
{
|
||||
|
|
@ -50,6 +51,7 @@ namespace Microsoft.AspNetCore.Authentication
|
|||
/// <summary>
|
||||
/// The <see cref="IAuthenticationHandler"/> type that handles this scheme.
|
||||
/// </summary>
|
||||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
|
||||
public Type HandlerType { get; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Microsoft.AspNetCore.Authentication
|
||||
{
|
||||
|
|
@ -32,6 +33,7 @@ namespace Microsoft.AspNetCore.Authentication
|
|||
/// <summary>
|
||||
/// The <see cref="IAuthenticationHandler"/> type responsible for this scheme.
|
||||
/// </summary>
|
||||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
|
||||
public Type? HandlerType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
|
@ -25,7 +26,7 @@ namespace Microsoft.AspNetCore.Authentication
|
|||
/// </summary>
|
||||
public virtual IServiceCollection Services { get; }
|
||||
|
||||
private AuthenticationBuilder AddSchemeHelper<TOptions, THandler>(string authenticationScheme, string? displayName, Action<TOptions>? configureOptions)
|
||||
private AuthenticationBuilder AddSchemeHelper<TOptions, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]THandler>(string authenticationScheme, string? displayName, Action<TOptions>? configureOptions)
|
||||
where TOptions : AuthenticationSchemeOptions, new()
|
||||
where THandler : class, IAuthenticationHandler
|
||||
{
|
||||
|
|
@ -57,7 +58,7 @@ namespace Microsoft.AspNetCore.Authentication
|
|||
/// <param name="displayName">The display name of this scheme.</param>
|
||||
/// <param name="configureOptions">Used to configure the scheme options.</param>
|
||||
/// <returns>The builder.</returns>
|
||||
public virtual AuthenticationBuilder AddScheme<TOptions, THandler>(string authenticationScheme, string? displayName, Action<TOptions>? configureOptions)
|
||||
public virtual AuthenticationBuilder AddScheme<TOptions, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]THandler>(string authenticationScheme, string? displayName, Action<TOptions>? configureOptions)
|
||||
where TOptions : AuthenticationSchemeOptions, new()
|
||||
where THandler : AuthenticationHandler<TOptions>
|
||||
=> AddSchemeHelper<TOptions, THandler>(authenticationScheme, displayName, configureOptions);
|
||||
|
|
@ -70,7 +71,7 @@ namespace Microsoft.AspNetCore.Authentication
|
|||
/// <param name="authenticationScheme">The name of this scheme.</param>
|
||||
/// <param name="configureOptions">Used to configure the scheme options.</param>
|
||||
/// <returns>The builder.</returns>
|
||||
public virtual AuthenticationBuilder AddScheme<TOptions, THandler>(string authenticationScheme, Action<TOptions>? configureOptions)
|
||||
public virtual AuthenticationBuilder AddScheme<TOptions, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]THandler>(string authenticationScheme, Action<TOptions>? configureOptions)
|
||||
where TOptions : AuthenticationSchemeOptions, new()
|
||||
where THandler : AuthenticationHandler<TOptions>
|
||||
=> AddScheme<TOptions, THandler>(authenticationScheme, displayName: null, configureOptions: configureOptions);
|
||||
|
|
@ -85,7 +86,7 @@ namespace Microsoft.AspNetCore.Authentication
|
|||
/// <param name="displayName">The display name of this scheme.</param>
|
||||
/// <param name="configureOptions">Used to configure the scheme options.</param>
|
||||
/// <returns>The builder.</returns>
|
||||
public virtual AuthenticationBuilder AddRemoteScheme<TOptions, THandler>(string authenticationScheme, string? displayName, Action<TOptions>? configureOptions)
|
||||
public virtual AuthenticationBuilder AddRemoteScheme<TOptions, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]THandler>(string authenticationScheme, string? displayName, Action<TOptions>? configureOptions)
|
||||
where TOptions : RemoteAuthenticationOptions, new()
|
||||
where THandler : RemoteAuthenticationHandler<TOptions>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication.OAuth;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
|
|
@ -17,12 +18,12 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
public static AuthenticationBuilder AddOAuth(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action<OAuthOptions> configureOptions)
|
||||
=> builder.AddOAuth<OAuthOptions, OAuthHandler<OAuthOptions>>(authenticationScheme, displayName, configureOptions);
|
||||
|
||||
public static AuthenticationBuilder AddOAuth<TOptions, THandler>(this AuthenticationBuilder builder, string authenticationScheme, Action<TOptions> configureOptions)
|
||||
public static AuthenticationBuilder AddOAuth<TOptions, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]THandler>(this AuthenticationBuilder builder, string authenticationScheme, Action<TOptions> configureOptions)
|
||||
where TOptions : OAuthOptions, new()
|
||||
where THandler : OAuthHandler<TOptions>
|
||||
=> builder.AddOAuth<TOptions, THandler>(authenticationScheme, OAuthDefaults.DisplayName, configureOptions);
|
||||
|
||||
public static AuthenticationBuilder AddOAuth<TOptions, THandler>(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action<TOptions> configureOptions)
|
||||
public static AuthenticationBuilder AddOAuth<TOptions, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]THandler>(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action<TOptions> configureOptions)
|
||||
where TOptions : OAuthOptions, new()
|
||||
where THandler : OAuthHandler<TOptions>
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue