From 6e54e06cfa5d9c3e43f68ab396664d70d22c6d20 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Sat, 6 Jun 2020 14:43:39 -0700 Subject: [PATCH] Add nullable to Auth.Abstractions, and Auth.Core (#22541) --- ...NetCore.Authentication.Abstractions.csproj | 1 + ....Authentication.Abstractions.netcoreapp.cs | 125 +++++++++--------- .../src/AuthenticateResult.cs | 20 +-- .../AuthenticationHttpContextExtensions.cs | 26 ++-- .../src/AuthenticationOptions.cs | 12 +- .../src/AuthenticationProperties.cs | 35 ++--- .../src/AuthenticationScheme.cs | 5 +- .../src/AuthenticationSchemeBuilder.cs | 14 +- .../src/AuthenticationTicket.cs | 4 +- .../src/AuthenticationToken.cs | 4 +- .../src/IAuthenticationHandler.cs | 4 +- .../src/IAuthenticationHandlerProvider.cs | 4 +- .../src/IAuthenticationSchemeProvider.cs | 14 +- .../src/IAuthenticationService.cs | 10 +- .../src/IAuthenticationSignInHandler.cs | 2 +- .../src/IAuthenticationSignOutHandler.cs | 2 +- ...NetCore.Authentication.Abstractions.csproj | 4 +- .../src/TokenExtensions.cs | 19 ++- ...soft.AspNetCore.Authentication.Core.csproj | 1 + ...pNetCore.Authentication.Core.netcoreapp.cs | 24 ++-- .../src/AuthenticationHandlerProvider.cs | 8 +- .../src/AuthenticationSchemeProvider.cs | 18 +-- .../src/AuthenticationService.cs | 16 +-- ...soft.AspNetCore.Authentication.Core.csproj | 1 + .../test/AuthenticationPropertiesTests.cs | 10 +- .../test/AuthenticationSchemeProviderTests.cs | 34 ++--- .../test/AuthenticationServiceTests.cs | 34 ++--- ...AspNetCore.Authentication.Core.Test.csproj | 1 + .../test/TokenExtensionTests.cs | 4 +- 29 files changed, 239 insertions(+), 217 deletions(-) diff --git a/src/Http/Authentication.Abstractions/ref/Microsoft.AspNetCore.Authentication.Abstractions.csproj b/src/Http/Authentication.Abstractions/ref/Microsoft.AspNetCore.Authentication.Abstractions.csproj index 8c27edb284..b188a0582d 100644 --- a/src/Http/Authentication.Abstractions/ref/Microsoft.AspNetCore.Authentication.Abstractions.csproj +++ b/src/Http/Authentication.Abstractions/ref/Microsoft.AspNetCore.Authentication.Abstractions.csproj @@ -2,6 +2,7 @@ $(DefaultNetCoreTargetFramework) + annotations diff --git a/src/Http/Authentication.Abstractions/ref/Microsoft.AspNetCore.Authentication.Abstractions.netcoreapp.cs b/src/Http/Authentication.Abstractions/ref/Microsoft.AspNetCore.Authentication.Abstractions.netcoreapp.cs index 58949cc877..8a790d9883 100644 --- a/src/Http/Authentication.Abstractions/ref/Microsoft.AspNetCore.Authentication.Abstractions.netcoreapp.cs +++ b/src/Http/Authentication.Abstractions/ref/Microsoft.AspNetCore.Authentication.Abstractions.netcoreapp.cs @@ -6,52 +6,52 @@ namespace Microsoft.AspNetCore.Authentication public partial class AuthenticateResult { protected AuthenticateResult() { } - public System.Exception Failure { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] protected set { } } + public System.Exception? Failure { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] protected set { } } public bool None { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] protected set { } } - public System.Security.Claims.ClaimsPrincipal Principal { get { throw null; } } - public Microsoft.AspNetCore.Authentication.AuthenticationProperties Properties { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] protected set { } } + public System.Security.Claims.ClaimsPrincipal? Principal { get { throw null; } } + public Microsoft.AspNetCore.Authentication.AuthenticationProperties? Properties { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] protected set { } } public bool Succeeded { get { throw null; } } - public Microsoft.AspNetCore.Authentication.AuthenticationTicket Ticket { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] protected set { } } + public Microsoft.AspNetCore.Authentication.AuthenticationTicket? Ticket { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] protected set { } } public Microsoft.AspNetCore.Authentication.AuthenticateResult Clone() { throw null; } - public static Microsoft.AspNetCore.Authentication.AuthenticateResult Fail(System.Exception failure) { throw null; } - public static Microsoft.AspNetCore.Authentication.AuthenticateResult Fail(System.Exception failure, Microsoft.AspNetCore.Authentication.AuthenticationProperties properties) { throw null; } - public static Microsoft.AspNetCore.Authentication.AuthenticateResult Fail(string failureMessage) { throw null; } - public static Microsoft.AspNetCore.Authentication.AuthenticateResult Fail(string failureMessage, Microsoft.AspNetCore.Authentication.AuthenticationProperties properties) { throw null; } + public static Microsoft.AspNetCore.Authentication.AuthenticateResult Fail(System.Exception? failure) { throw null; } + public static Microsoft.AspNetCore.Authentication.AuthenticateResult Fail(System.Exception? failure, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) { throw null; } + public static Microsoft.AspNetCore.Authentication.AuthenticateResult Fail(string? failureMessage) { throw null; } + public static Microsoft.AspNetCore.Authentication.AuthenticateResult Fail(string? failureMessage, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) { throw null; } public static Microsoft.AspNetCore.Authentication.AuthenticateResult NoResult() { throw null; } public static Microsoft.AspNetCore.Authentication.AuthenticateResult Success(Microsoft.AspNetCore.Authentication.AuthenticationTicket ticket) { throw null; } } public static partial class AuthenticationHttpContextExtensions { - public static System.Threading.Tasks.Task AuthenticateAsync(this Microsoft.AspNetCore.Http.HttpContext context) { throw null; } - public static System.Threading.Tasks.Task AuthenticateAsync(this Microsoft.AspNetCore.Http.HttpContext context, string scheme) { throw null; } + public static System.Threading.Tasks.Task AuthenticateAsync(this Microsoft.AspNetCore.Http.HttpContext context) { throw null; } + public static System.Threading.Tasks.Task AuthenticateAsync(this Microsoft.AspNetCore.Http.HttpContext context, string? scheme) { throw null; } public static System.Threading.Tasks.Task ChallengeAsync(this Microsoft.AspNetCore.Http.HttpContext context) { throw null; } - public static System.Threading.Tasks.Task ChallengeAsync(this Microsoft.AspNetCore.Http.HttpContext context, Microsoft.AspNetCore.Authentication.AuthenticationProperties properties) { throw null; } + public static System.Threading.Tasks.Task ChallengeAsync(this Microsoft.AspNetCore.Http.HttpContext context, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) { throw null; } public static System.Threading.Tasks.Task ChallengeAsync(this Microsoft.AspNetCore.Http.HttpContext context, string scheme) { throw null; } - public static System.Threading.Tasks.Task ChallengeAsync(this Microsoft.AspNetCore.Http.HttpContext context, string scheme, Microsoft.AspNetCore.Authentication.AuthenticationProperties properties) { throw null; } + public static System.Threading.Tasks.Task ChallengeAsync(this Microsoft.AspNetCore.Http.HttpContext context, string? scheme, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) { throw null; } public static System.Threading.Tasks.Task ForbidAsync(this Microsoft.AspNetCore.Http.HttpContext context) { throw null; } - public static System.Threading.Tasks.Task ForbidAsync(this Microsoft.AspNetCore.Http.HttpContext context, Microsoft.AspNetCore.Authentication.AuthenticationProperties properties) { throw null; } + public static System.Threading.Tasks.Task ForbidAsync(this Microsoft.AspNetCore.Http.HttpContext context, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) { throw null; } public static System.Threading.Tasks.Task ForbidAsync(this Microsoft.AspNetCore.Http.HttpContext context, string scheme) { throw null; } - public static System.Threading.Tasks.Task ForbidAsync(this Microsoft.AspNetCore.Http.HttpContext context, string scheme, Microsoft.AspNetCore.Authentication.AuthenticationProperties properties) { throw null; } - public static System.Threading.Tasks.Task GetTokenAsync(this Microsoft.AspNetCore.Http.HttpContext context, string tokenName) { throw null; } - public static System.Threading.Tasks.Task GetTokenAsync(this Microsoft.AspNetCore.Http.HttpContext context, string scheme, string tokenName) { throw null; } + public static System.Threading.Tasks.Task ForbidAsync(this Microsoft.AspNetCore.Http.HttpContext context, string? scheme, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) { throw null; } + public static System.Threading.Tasks.Task GetTokenAsync(this Microsoft.AspNetCore.Http.HttpContext context, string tokenName) { throw null; } + public static System.Threading.Tasks.Task GetTokenAsync(this Microsoft.AspNetCore.Http.HttpContext context, string? scheme, string tokenName) { throw null; } public static System.Threading.Tasks.Task SignInAsync(this Microsoft.AspNetCore.Http.HttpContext context, System.Security.Claims.ClaimsPrincipal principal) { throw null; } - public static System.Threading.Tasks.Task SignInAsync(this Microsoft.AspNetCore.Http.HttpContext context, System.Security.Claims.ClaimsPrincipal principal, Microsoft.AspNetCore.Authentication.AuthenticationProperties properties) { throw null; } + public static System.Threading.Tasks.Task SignInAsync(this Microsoft.AspNetCore.Http.HttpContext context, System.Security.Claims.ClaimsPrincipal principal, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) { throw null; } public static System.Threading.Tasks.Task SignInAsync(this Microsoft.AspNetCore.Http.HttpContext context, string scheme, System.Security.Claims.ClaimsPrincipal principal) { throw null; } - public static System.Threading.Tasks.Task SignInAsync(this Microsoft.AspNetCore.Http.HttpContext context, string scheme, System.Security.Claims.ClaimsPrincipal principal, Microsoft.AspNetCore.Authentication.AuthenticationProperties properties) { throw null; } + public static System.Threading.Tasks.Task SignInAsync(this Microsoft.AspNetCore.Http.HttpContext context, string? scheme, System.Security.Claims.ClaimsPrincipal principal, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) { throw null; } public static System.Threading.Tasks.Task SignOutAsync(this Microsoft.AspNetCore.Http.HttpContext context) { throw null; } - public static System.Threading.Tasks.Task SignOutAsync(this Microsoft.AspNetCore.Http.HttpContext context, Microsoft.AspNetCore.Authentication.AuthenticationProperties properties) { throw null; } - public static System.Threading.Tasks.Task SignOutAsync(this Microsoft.AspNetCore.Http.HttpContext context, string scheme) { throw null; } - public static System.Threading.Tasks.Task SignOutAsync(this Microsoft.AspNetCore.Http.HttpContext context, string scheme, Microsoft.AspNetCore.Authentication.AuthenticationProperties properties) { throw null; } + public static System.Threading.Tasks.Task SignOutAsync(this Microsoft.AspNetCore.Http.HttpContext context, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) { throw null; } + public static System.Threading.Tasks.Task SignOutAsync(this Microsoft.AspNetCore.Http.HttpContext context, string? scheme) { throw null; } + public static System.Threading.Tasks.Task SignOutAsync(this Microsoft.AspNetCore.Http.HttpContext context, string? scheme, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) { throw null; } } public partial class AuthenticationOptions { public AuthenticationOptions() { } - public string DefaultAuthenticateScheme { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } - public string DefaultChallengeScheme { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } - public string DefaultForbidScheme { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } - public string DefaultScheme { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } - public string DefaultSignInScheme { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } - public string DefaultSignOutScheme { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public string? DefaultAuthenticateScheme { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public string? DefaultChallengeScheme { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public string? DefaultForbidScheme { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public string? DefaultScheme { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public string? DefaultSignInScheme { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public string? DefaultSignOutScheme { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public bool RequireAuthenticatedSignIn { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public System.Collections.Generic.IDictionary SchemeMap { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } public System.Collections.Generic.IEnumerable Schemes { get { throw null; } } @@ -61,45 +61,46 @@ namespace Microsoft.AspNetCore.Authentication public partial class AuthenticationProperties { public AuthenticationProperties() { } - public AuthenticationProperties(System.Collections.Generic.IDictionary items) { } - public AuthenticationProperties(System.Collections.Generic.IDictionary items, System.Collections.Generic.IDictionary parameters) { } + public AuthenticationProperties(System.Collections.Generic.IDictionary items) { } + public AuthenticationProperties(System.Collections.Generic.IDictionary? items, System.Collections.Generic.IDictionary? parameters) { } public bool? AllowRefresh { get { throw null; } set { } } public System.DateTimeOffset? ExpiresUtc { get { throw null; } set { } } public bool IsPersistent { get { throw null; } set { } } public System.DateTimeOffset? IssuedUtc { get { throw null; } set { } } - public System.Collections.Generic.IDictionary Items { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } - public System.Collections.Generic.IDictionary Parameters { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } - public string RedirectUri { get { throw null; } set { } } + public System.Collections.Generic.IDictionary Items { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } + public System.Collections.Generic.IDictionary Parameters { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } + public string? RedirectUri { get { throw null; } set { } } public Microsoft.AspNetCore.Authentication.AuthenticationProperties Clone() { throw null; } protected bool? GetBool(string key) { throw null; } protected System.DateTimeOffset? GetDateTimeOffset(string key) { throw null; } + [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] public T GetParameter(string key) { throw null; } - public string GetString(string key) { throw null; } + public string? GetString(string key) { throw null; } protected void SetBool(string key, bool? value) { } protected void SetDateTimeOffset(string key, System.DateTimeOffset? value) { } - public void SetParameter(string key, T value) { } - public void SetString(string key, string value) { } + public void SetParameter(string key, [System.Diagnostics.CodeAnalysis.MaybeNullAttribute] T value) { } + public void SetString(string key, string? value) { } } public partial class AuthenticationScheme { - public AuthenticationScheme(string name, string displayName, System.Type handlerType) { } - public string DisplayName { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } + public AuthenticationScheme(string name, string? displayName, System.Type handlerType) { } + public string? DisplayName { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } public System.Type HandlerType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } public string Name { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } } public partial class AuthenticationSchemeBuilder { public AuthenticationSchemeBuilder(string name) { } - public string DisplayName { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } - public System.Type HandlerType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public string? DisplayName { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public System.Type? HandlerType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } public string Name { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } public Microsoft.AspNetCore.Authentication.AuthenticationScheme Build() { throw null; } } public partial class AuthenticationTicket { - public AuthenticationTicket(System.Security.Claims.ClaimsPrincipal principal, Microsoft.AspNetCore.Authentication.AuthenticationProperties properties, string authenticationScheme) { } + public AuthenticationTicket(System.Security.Claims.ClaimsPrincipal principal, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties, string? authenticationScheme) { } public AuthenticationTicket(System.Security.Claims.ClaimsPrincipal principal, string authenticationScheme) { } - public string AuthenticationScheme { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } + public string? AuthenticationScheme { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } public System.Security.Claims.ClaimsPrincipal Principal { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } public Microsoft.AspNetCore.Authentication.AuthenticationProperties Properties { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } public Microsoft.AspNetCore.Authentication.AuthenticationTicket Clone() { throw null; } @@ -107,16 +108,16 @@ namespace Microsoft.AspNetCore.Authentication public partial class AuthenticationToken { public AuthenticationToken() { } - public string Name { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } - public string Value { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public string? Name { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } + public string? Value { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } } } public static partial class AuthenticationTokenExtensions { - public static System.Threading.Tasks.Task GetTokenAsync(this Microsoft.AspNetCore.Authentication.IAuthenticationService auth, Microsoft.AspNetCore.Http.HttpContext context, string tokenName) { throw null; } + public static System.Threading.Tasks.Task GetTokenAsync(this Microsoft.AspNetCore.Authentication.IAuthenticationService auth, Microsoft.AspNetCore.Http.HttpContext context, string tokenName) { throw null; } [System.Diagnostics.DebuggerStepThroughAttribute] - public static System.Threading.Tasks.Task GetTokenAsync(this Microsoft.AspNetCore.Authentication.IAuthenticationService auth, Microsoft.AspNetCore.Http.HttpContext context, string scheme, string tokenName) { throw null; } + public static System.Threading.Tasks.Task GetTokenAsync(this Microsoft.AspNetCore.Authentication.IAuthenticationService auth, Microsoft.AspNetCore.Http.HttpContext context, string? scheme, string tokenName) { throw null; } public static System.Collections.Generic.IEnumerable GetTokens(this Microsoft.AspNetCore.Authentication.AuthenticationProperties properties) { throw null; } - public static string GetTokenValue(this Microsoft.AspNetCore.Authentication.AuthenticationProperties properties, string tokenName) { throw null; } + public static string? GetTokenValue(this Microsoft.AspNetCore.Authentication.AuthenticationProperties properties, string tokenName) { throw null; } public static void StoreTokens(this Microsoft.AspNetCore.Authentication.AuthenticationProperties properties, System.Collections.Generic.IEnumerable tokens) { } public static bool UpdateTokenValue(this Microsoft.AspNetCore.Authentication.AuthenticationProperties properties, string tokenName, string tokenValue) { throw null; } } @@ -128,13 +129,13 @@ namespace Microsoft.AspNetCore.Authentication public partial interface IAuthenticationHandler { System.Threading.Tasks.Task AuthenticateAsync(); - System.Threading.Tasks.Task ChallengeAsync(Microsoft.AspNetCore.Authentication.AuthenticationProperties properties); - System.Threading.Tasks.Task ForbidAsync(Microsoft.AspNetCore.Authentication.AuthenticationProperties properties); + System.Threading.Tasks.Task ChallengeAsync(Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties); + System.Threading.Tasks.Task ForbidAsync(Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties); System.Threading.Tasks.Task InitializeAsync(Microsoft.AspNetCore.Authentication.AuthenticationScheme scheme, Microsoft.AspNetCore.Http.HttpContext context); } public partial interface IAuthenticationHandlerProvider { - System.Threading.Tasks.Task GetHandlerAsync(Microsoft.AspNetCore.Http.HttpContext context, string authenticationScheme); + System.Threading.Tasks.Task GetHandlerAsync(Microsoft.AspNetCore.Http.HttpContext context, string authenticationScheme); } public partial interface IAuthenticationRequestHandler : Microsoft.AspNetCore.Authentication.IAuthenticationHandler { @@ -144,31 +145,31 @@ namespace Microsoft.AspNetCore.Authentication { void AddScheme(Microsoft.AspNetCore.Authentication.AuthenticationScheme scheme); System.Threading.Tasks.Task> GetAllSchemesAsync(); - System.Threading.Tasks.Task GetDefaultAuthenticateSchemeAsync(); - System.Threading.Tasks.Task GetDefaultChallengeSchemeAsync(); - System.Threading.Tasks.Task GetDefaultForbidSchemeAsync(); - System.Threading.Tasks.Task GetDefaultSignInSchemeAsync(); - System.Threading.Tasks.Task GetDefaultSignOutSchemeAsync(); + System.Threading.Tasks.Task GetDefaultAuthenticateSchemeAsync(); + System.Threading.Tasks.Task GetDefaultChallengeSchemeAsync(); + System.Threading.Tasks.Task GetDefaultForbidSchemeAsync(); + System.Threading.Tasks.Task GetDefaultSignInSchemeAsync(); + System.Threading.Tasks.Task GetDefaultSignOutSchemeAsync(); System.Threading.Tasks.Task> GetRequestHandlerSchemesAsync(); - System.Threading.Tasks.Task GetSchemeAsync(string name); + System.Threading.Tasks.Task GetSchemeAsync(string name); void RemoveScheme(string name); bool TryAddScheme(Microsoft.AspNetCore.Authentication.AuthenticationScheme scheme) { throw null; } } public partial interface IAuthenticationService { - System.Threading.Tasks.Task AuthenticateAsync(Microsoft.AspNetCore.Http.HttpContext context, string scheme); - System.Threading.Tasks.Task ChallengeAsync(Microsoft.AspNetCore.Http.HttpContext context, string scheme, Microsoft.AspNetCore.Authentication.AuthenticationProperties properties); - System.Threading.Tasks.Task ForbidAsync(Microsoft.AspNetCore.Http.HttpContext context, string scheme, Microsoft.AspNetCore.Authentication.AuthenticationProperties properties); - System.Threading.Tasks.Task SignInAsync(Microsoft.AspNetCore.Http.HttpContext context, string scheme, System.Security.Claims.ClaimsPrincipal principal, Microsoft.AspNetCore.Authentication.AuthenticationProperties properties); - System.Threading.Tasks.Task SignOutAsync(Microsoft.AspNetCore.Http.HttpContext context, string scheme, Microsoft.AspNetCore.Authentication.AuthenticationProperties properties); + System.Threading.Tasks.Task AuthenticateAsync(Microsoft.AspNetCore.Http.HttpContext context, string? scheme); + System.Threading.Tasks.Task ChallengeAsync(Microsoft.AspNetCore.Http.HttpContext context, string? scheme, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties); + System.Threading.Tasks.Task ForbidAsync(Microsoft.AspNetCore.Http.HttpContext context, string? scheme, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties); + System.Threading.Tasks.Task SignInAsync(Microsoft.AspNetCore.Http.HttpContext context, string? scheme, System.Security.Claims.ClaimsPrincipal principal, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties); + System.Threading.Tasks.Task SignOutAsync(Microsoft.AspNetCore.Http.HttpContext context, string? scheme, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties); } public partial interface IAuthenticationSignInHandler : Microsoft.AspNetCore.Authentication.IAuthenticationHandler, Microsoft.AspNetCore.Authentication.IAuthenticationSignOutHandler { - System.Threading.Tasks.Task SignInAsync(System.Security.Claims.ClaimsPrincipal user, Microsoft.AspNetCore.Authentication.AuthenticationProperties properties); + System.Threading.Tasks.Task SignInAsync(System.Security.Claims.ClaimsPrincipal user, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties); } public partial interface IAuthenticationSignOutHandler : Microsoft.AspNetCore.Authentication.IAuthenticationHandler { - System.Threading.Tasks.Task SignOutAsync(Microsoft.AspNetCore.Authentication.AuthenticationProperties properties); + System.Threading.Tasks.Task SignOutAsync(Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties); } public partial interface IClaimsTransformation { diff --git a/src/Http/Authentication.Abstractions/src/AuthenticateResult.cs b/src/Http/Authentication.Abstractions/src/AuthenticateResult.cs index 6d250b0507..f801ce5308 100644 --- a/src/Http/Authentication.Abstractions/src/AuthenticateResult.cs +++ b/src/Http/Authentication.Abstractions/src/AuthenticateResult.cs @@ -24,22 +24,22 @@ namespace Microsoft.AspNetCore.Authentication /// /// The authentication ticket. /// - public AuthenticationTicket Ticket { get; protected set; } + public AuthenticationTicket? Ticket { get; protected set; } /// /// Gets the claims-principal with authenticated user identities. /// - public ClaimsPrincipal Principal => Ticket?.Principal; + public ClaimsPrincipal? Principal => Ticket?.Principal; /// /// Additional state values for the authentication session. /// - public AuthenticationProperties Properties { get; protected set; } + public AuthenticationProperties? Properties { get; protected set; } /// /// Holds failure information from the authentication. /// - public Exception Failure { get; protected set; } + public Exception? Failure { get; protected set; } /// /// Indicates that there was no information returned for this authentication scheme. @@ -58,11 +58,11 @@ namespace Microsoft.AspNetCore.Authentication } if (Failure != null) { - return Fail(Failure, Properties.Clone()); + return Fail(Failure, Properties?.Clone()); } if (Succeeded) { - return Success(Ticket.Clone()); + return Success(Ticket!.Clone()); } // This shouldn't happen throw new NotImplementedException(); @@ -96,7 +96,7 @@ namespace Microsoft.AspNetCore.Authentication /// /// The failure exception. /// The result. - public static AuthenticateResult Fail(Exception failure) + public static AuthenticateResult Fail(Exception? failure) { return new AuthenticateResult() { Failure = failure }; } @@ -107,7 +107,7 @@ namespace Microsoft.AspNetCore.Authentication /// The failure exception. /// Additional state values for the authentication session. /// The result. - public static AuthenticateResult Fail(Exception failure, AuthenticationProperties properties) + public static AuthenticateResult Fail(Exception? failure, AuthenticationProperties? properties) { return new AuthenticateResult() { Failure = failure, Properties = properties }; } @@ -117,7 +117,7 @@ namespace Microsoft.AspNetCore.Authentication /// /// The failure message. /// The result. - public static AuthenticateResult Fail(string failureMessage) + public static AuthenticateResult Fail(string? failureMessage) => Fail(new Exception(failureMessage)); /// @@ -126,7 +126,7 @@ namespace Microsoft.AspNetCore.Authentication /// The failure message. /// Additional state values for the authentication session. /// The result. - public static AuthenticateResult Fail(string failureMessage, AuthenticationProperties properties) + public static AuthenticateResult Fail(string? failureMessage, AuthenticationProperties? properties) => Fail(new Exception(failureMessage), properties); } } diff --git a/src/Http/Authentication.Abstractions/src/AuthenticationHttpContextExtensions.cs b/src/Http/Authentication.Abstractions/src/AuthenticationHttpContextExtensions.cs index 0b40426098..e831311e6e 100644 --- a/src/Http/Authentication.Abstractions/src/AuthenticationHttpContextExtensions.cs +++ b/src/Http/Authentication.Abstractions/src/AuthenticationHttpContextExtensions.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Authentication /// /// The context. /// The . - public static Task AuthenticateAsync(this HttpContext context) => + public static Task AuthenticateAsync(this HttpContext context) => context.AuthenticateAsync(scheme: null); /// @@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Authentication /// The context. /// The name of the authentication scheme. /// The . - public static Task AuthenticateAsync(this HttpContext context, string scheme) => + public static Task AuthenticateAsync(this HttpContext context, string? scheme) => context.RequestServices.GetRequiredService().AuthenticateAsync(context, scheme); /// @@ -53,7 +53,7 @@ namespace Microsoft.AspNetCore.Authentication /// The context. /// The properties. /// The task. - public static Task ChallengeAsync(this HttpContext context, AuthenticationProperties properties) => + public static Task ChallengeAsync(this HttpContext context, AuthenticationProperties? properties) => context.ChallengeAsync(scheme: null, properties: properties); /// @@ -63,7 +63,7 @@ namespace Microsoft.AspNetCore.Authentication /// The name of the authentication scheme. /// The properties. /// The task. - public static Task ChallengeAsync(this HttpContext context, string scheme, AuthenticationProperties properties) => + public static Task ChallengeAsync(this HttpContext context, string? scheme, AuthenticationProperties? properties) => context.RequestServices.GetRequiredService().ChallengeAsync(context, scheme, properties); /// @@ -89,7 +89,7 @@ namespace Microsoft.AspNetCore.Authentication /// The context. /// The properties. /// The task. - public static Task ForbidAsync(this HttpContext context, AuthenticationProperties properties) => + public static Task ForbidAsync(this HttpContext context, AuthenticationProperties? properties) => context.ForbidAsync(scheme: null, properties: properties); /// @@ -99,7 +99,7 @@ namespace Microsoft.AspNetCore.Authentication /// The name of the authentication scheme. /// The properties. /// The task. - public static Task ForbidAsync(this HttpContext context, string scheme, AuthenticationProperties properties) => + public static Task ForbidAsync(this HttpContext context, string? scheme, AuthenticationProperties? properties) => context.RequestServices.GetRequiredService().ForbidAsync(context, scheme, properties); /// @@ -128,7 +128,7 @@ namespace Microsoft.AspNetCore.Authentication /// The user. /// The properties. /// The task. - public static Task SignInAsync(this HttpContext context, ClaimsPrincipal principal, AuthenticationProperties properties) => + public static Task SignInAsync(this HttpContext context, ClaimsPrincipal principal, AuthenticationProperties? properties) => context.SignInAsync(scheme: null, principal: principal, properties: properties); /// @@ -139,7 +139,7 @@ namespace Microsoft.AspNetCore.Authentication /// The user. /// The properties. /// The task. - public static Task SignInAsync(this HttpContext context, string scheme, ClaimsPrincipal principal, AuthenticationProperties properties) => + public static Task SignInAsync(this HttpContext context, string? scheme, ClaimsPrincipal principal, AuthenticationProperties? properties) => context.RequestServices.GetRequiredService().SignInAsync(context, scheme, principal, properties); /// @@ -155,7 +155,7 @@ namespace Microsoft.AspNetCore.Authentication /// The context. /// The properties. /// The task. - public static Task SignOutAsync(this HttpContext context, AuthenticationProperties properties) => context.SignOutAsync(scheme: null, properties: properties); + public static Task SignOutAsync(this HttpContext context, AuthenticationProperties? properties) => context.SignOutAsync(scheme: null, properties: properties); /// /// Extension method for SignOut. @@ -163,7 +163,7 @@ namespace Microsoft.AspNetCore.Authentication /// The context. /// The name of the authentication scheme. /// The task. - public static Task SignOutAsync(this HttpContext context, string scheme) => context.SignOutAsync(scheme, properties: null); + public static Task SignOutAsync(this HttpContext context, string? scheme) => context.SignOutAsync(scheme, properties: null); /// /// Extension method for SignOut. @@ -172,7 +172,7 @@ namespace Microsoft.AspNetCore.Authentication /// The name of the authentication scheme. /// The properties. /// The task. - public static Task SignOutAsync(this HttpContext context, string scheme, AuthenticationProperties properties) => + public static Task SignOutAsync(this HttpContext context, string? scheme, AuthenticationProperties? properties) => context.RequestServices.GetRequiredService().SignOutAsync(context, scheme, properties); /// @@ -182,7 +182,7 @@ namespace Microsoft.AspNetCore.Authentication /// The name of the authentication scheme. /// The name of the token. /// The value of the token. - public static Task GetTokenAsync(this HttpContext context, string scheme, string tokenName) => + public static Task GetTokenAsync(this HttpContext context, string? scheme, string tokenName) => context.RequestServices.GetRequiredService().GetTokenAsync(context, scheme, tokenName); /// @@ -191,7 +191,7 @@ namespace Microsoft.AspNetCore.Authentication /// The context. /// The name of the token. /// The value of the token. - public static Task GetTokenAsync(this HttpContext context, string tokenName) => + public static Task GetTokenAsync(this HttpContext context, string tokenName) => context.RequestServices.GetRequiredService().GetTokenAsync(context, tokenName); } } diff --git a/src/Http/Authentication.Abstractions/src/AuthenticationOptions.cs b/src/Http/Authentication.Abstractions/src/AuthenticationOptions.cs index 2fc213d718..ee76d6d1e0 100644 --- a/src/Http/Authentication.Abstractions/src/AuthenticationOptions.cs +++ b/src/Http/Authentication.Abstractions/src/AuthenticationOptions.cs @@ -64,32 +64,32 @@ namespace Microsoft.AspNetCore.Authentication /// /// Used as the fallback default scheme for all the other defaults. /// - public string DefaultScheme { get; set; } + public string? DefaultScheme { get; set; } /// /// Used as the default scheme by . /// - public string DefaultAuthenticateScheme { get; set; } + public string? DefaultAuthenticateScheme { get; set; } /// /// Used as the default scheme by . /// - public string DefaultSignInScheme { get; set; } + public string? DefaultSignInScheme { get; set; } /// /// Used as the default scheme by . /// - public string DefaultSignOutScheme { get; set; } + public string? DefaultSignOutScheme { get; set; } /// /// Used as the default scheme by . /// - public string DefaultChallengeScheme { get; set; } + public string? DefaultChallengeScheme { get; set; } /// /// Used as the default scheme by . /// - public string DefaultForbidScheme { get; set; } + public string? DefaultForbidScheme { get; set; } /// /// If true, SignIn should throw if attempted with a ClaimsPrincipal.Identity.IsAuthenticated = false. diff --git a/src/Http/Authentication.Abstractions/src/AuthenticationProperties.cs b/src/Http/Authentication.Abstractions/src/AuthenticationProperties.cs index 491e2552e8..28afa3a7de 100644 --- a/src/Http/Authentication.Abstractions/src/AuthenticationProperties.cs +++ b/src/Http/Authentication.Abstractions/src/AuthenticationProperties.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Globalization; namespace Microsoft.AspNetCore.Authentication @@ -30,7 +31,7 @@ namespace Microsoft.AspNetCore.Authentication /// Initializes a new instance of the class. /// /// State values dictionary to use. - public AuthenticationProperties(IDictionary items) + public AuthenticationProperties(IDictionary items) : this(items, parameters: null) { } @@ -39,10 +40,10 @@ namespace Microsoft.AspNetCore.Authentication /// /// State values dictionary to use. /// Parameters dictionary to use. - public AuthenticationProperties(IDictionary items, IDictionary parameters) + public AuthenticationProperties(IDictionary? items, IDictionary? parameters) { - Items = items ?? new Dictionary(StringComparer.Ordinal); - Parameters = parameters ?? new Dictionary(StringComparer.Ordinal); + Items = items ?? new Dictionary(StringComparer.Ordinal); + Parameters = parameters ?? new Dictionary(StringComparer.Ordinal); } /// @@ -50,19 +51,20 @@ namespace Microsoft.AspNetCore.Authentication /// /// A copy. public AuthenticationProperties Clone() - => new AuthenticationProperties(new Dictionary(Items, StringComparer.Ordinal), - new Dictionary(Parameters, StringComparer.Ordinal)); + => new AuthenticationProperties( + new Dictionary(Items, StringComparer.Ordinal), + new Dictionary(Parameters, StringComparer.Ordinal)); /// /// State values about the authentication session. /// - public IDictionary Items { get; } + public IDictionary Items { get; } /// /// Collection of parameters that are passed to the authentication handler. These are not intended for /// serialization or persistence, only for flowing data between call sites. /// - public IDictionary Parameters { get; } + public IDictionary Parameters { get; } /// /// Gets or sets whether the authentication session is persisted across multiple requests. @@ -76,7 +78,7 @@ namespace Microsoft.AspNetCore.Authentication /// /// Gets or sets the full path or absolute URI to be used as an http redirect response value. /// - public string RedirectUri + public string? RedirectUri { get => GetString(RedirectUriKey); set => SetString(RedirectUriKey, value); @@ -114,9 +116,9 @@ namespace Microsoft.AspNetCore.Authentication /// /// Property key. /// Retrieved value or null if the property is not set. - public string GetString(string key) + public string? GetString(string key) { - return Items.TryGetValue(key, out string value) ? value : null; + return Items.TryGetValue(key, out var value) ? value : null; } /// @@ -124,7 +126,7 @@ namespace Microsoft.AspNetCore.Authentication /// /// Property key. /// Value to set or null to remove the property. - public void SetString(string key, string value) + public void SetString(string key, string? value) { if (value != null) { @@ -142,6 +144,7 @@ namespace Microsoft.AspNetCore.Authentication /// Parameter type. /// Parameter key. /// Retrieved value or the default value if the property is not set. + [return: MaybeNull] public T GetParameter(string key) => Parameters.TryGetValue(key, out var obj) && obj is T value ? value : default; @@ -151,7 +154,7 @@ namespace Microsoft.AspNetCore.Authentication /// Parameter type. /// Parameter key. /// Value to set. - public void SetParameter(string key, T value) + public void SetParameter(string key, [MaybeNull] T value) => Parameters[key] = value; /// @@ -161,7 +164,7 @@ namespace Microsoft.AspNetCore.Authentication /// Retrieved value or null if the property is not set. protected bool? GetBool(string key) { - if (Items.TryGetValue(key, out string value) && bool.TryParse(value, out bool boolValue)) + if (Items.TryGetValue(key, out var value) && bool.TryParse(value, out var boolValue)) { return boolValue; } @@ -192,8 +195,8 @@ namespace Microsoft.AspNetCore.Authentication /// Retrieved value or null if the property is not set. protected DateTimeOffset? GetDateTimeOffset(string key) { - if (Items.TryGetValue(key, out string value) - && DateTimeOffset.TryParseExact(value, UtcDateTimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out DateTimeOffset dateTimeOffset)) + if (Items.TryGetValue(key, out var value) + && DateTimeOffset.TryParseExact(value, UtcDateTimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out var dateTimeOffset)) { return dateTimeOffset; } diff --git a/src/Http/Authentication.Abstractions/src/AuthenticationScheme.cs b/src/Http/Authentication.Abstractions/src/AuthenticationScheme.cs index a72dc893ed..a268cce022 100644 --- a/src/Http/Authentication.Abstractions/src/AuthenticationScheme.cs +++ b/src/Http/Authentication.Abstractions/src/AuthenticationScheme.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Reflection; namespace Microsoft.AspNetCore.Authentication { @@ -18,7 +17,7 @@ namespace Microsoft.AspNetCore.Authentication /// The name for the authentication scheme. /// The display name for the authentication scheme. /// The type that handles this scheme. - public AuthenticationScheme(string name, string displayName, Type handlerType) + public AuthenticationScheme(string name, string? displayName, Type handlerType) { if (name == null) { @@ -46,7 +45,7 @@ namespace Microsoft.AspNetCore.Authentication /// /// The display name for the scheme. Null is valid and used for non user facing schemes. /// - public string DisplayName { get; } + public string? DisplayName { get; } /// /// The type that handles this scheme. diff --git a/src/Http/Authentication.Abstractions/src/AuthenticationSchemeBuilder.cs b/src/Http/Authentication.Abstractions/src/AuthenticationSchemeBuilder.cs index 30e843c028..7139de0a2f 100644 --- a/src/Http/Authentication.Abstractions/src/AuthenticationSchemeBuilder.cs +++ b/src/Http/Authentication.Abstractions/src/AuthenticationSchemeBuilder.cs @@ -27,17 +27,25 @@ namespace Microsoft.AspNetCore.Authentication /// /// The display name for the scheme being built. /// - public string DisplayName { get; set; } + public string? DisplayName { get; set; } /// /// The type responsible for this scheme. /// - public Type HandlerType { get; set; } + public Type? HandlerType { get; set; } /// /// Builds the instance. /// /// - public AuthenticationScheme Build() => new AuthenticationScheme(Name, DisplayName, HandlerType); + public AuthenticationScheme Build() + { + if (HandlerType is null) + { + throw new InvalidOperationException($"{nameof(HandlerType)} must be configured to build an {nameof(AuthenticationScheme)}."); + } + + return new AuthenticationScheme(Name, DisplayName, HandlerType); + } } } diff --git a/src/Http/Authentication.Abstractions/src/AuthenticationTicket.cs b/src/Http/Authentication.Abstractions/src/AuthenticationTicket.cs index 97b93afdde..4960060787 100644 --- a/src/Http/Authentication.Abstractions/src/AuthenticationTicket.cs +++ b/src/Http/Authentication.Abstractions/src/AuthenticationTicket.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Authentication /// the that represents the authenticated user. /// additional properties that can be consumed by the user or runtime. /// the authentication middleware that was responsible for this ticket. - public AuthenticationTicket(ClaimsPrincipal principal, AuthenticationProperties properties, string authenticationScheme) + public AuthenticationTicket(ClaimsPrincipal principal, AuthenticationProperties? properties, string? authenticationScheme) { if (principal == null) { @@ -41,7 +41,7 @@ namespace Microsoft.AspNetCore.Authentication /// /// Gets the authentication type. /// - public string AuthenticationScheme { get; private set; } + public string? AuthenticationScheme { get; private set; } /// /// Gets the claims-principal with authenticated user identities. diff --git a/src/Http/Authentication.Abstractions/src/AuthenticationToken.cs b/src/Http/Authentication.Abstractions/src/AuthenticationToken.cs index e188e98823..88c5d337ea 100644 --- a/src/Http/Authentication.Abstractions/src/AuthenticationToken.cs +++ b/src/Http/Authentication.Abstractions/src/AuthenticationToken.cs @@ -12,11 +12,11 @@ namespace Microsoft.AspNetCore.Authentication /// /// Name. /// - public string Name { get; set; } + public string? Name { get; set; } /// /// Value. /// - public string Value { get; set; } + public string? Value { get; set; } } } diff --git a/src/Http/Authentication.Abstractions/src/IAuthenticationHandler.cs b/src/Http/Authentication.Abstractions/src/IAuthenticationHandler.cs index aeb373e18e..8287274a8f 100644 --- a/src/Http/Authentication.Abstractions/src/IAuthenticationHandler.cs +++ b/src/Http/Authentication.Abstractions/src/IAuthenticationHandler.cs @@ -30,13 +30,13 @@ namespace Microsoft.AspNetCore.Authentication /// /// The that contains the extra meta-data arriving with the authentication. /// A task. - Task ChallengeAsync(AuthenticationProperties properties); + Task ChallengeAsync(AuthenticationProperties? properties); /// /// Forbid behavior. /// /// The that contains the extra meta-data arriving with the authentication. /// A task. - Task ForbidAsync(AuthenticationProperties properties); + Task ForbidAsync(AuthenticationProperties? properties); } } diff --git a/src/Http/Authentication.Abstractions/src/IAuthenticationHandlerProvider.cs b/src/Http/Authentication.Abstractions/src/IAuthenticationHandlerProvider.cs index 0507f51d61..43e2438f13 100644 --- a/src/Http/Authentication.Abstractions/src/IAuthenticationHandlerProvider.cs +++ b/src/Http/Authentication.Abstractions/src/IAuthenticationHandlerProvider.cs @@ -17,6 +17,6 @@ namespace Microsoft.AspNetCore.Authentication /// The context. /// The name of the authentication scheme being handled. /// The handler instance. - Task GetHandlerAsync(HttpContext context, string authenticationScheme); + Task GetHandlerAsync(HttpContext context, string authenticationScheme); } -} \ No newline at end of file +} diff --git a/src/Http/Authentication.Abstractions/src/IAuthenticationSchemeProvider.cs b/src/Http/Authentication.Abstractions/src/IAuthenticationSchemeProvider.cs index d0f54d74d0..fc7027f3d8 100644 --- a/src/Http/Authentication.Abstractions/src/IAuthenticationSchemeProvider.cs +++ b/src/Http/Authentication.Abstractions/src/IAuthenticationSchemeProvider.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Authentication /// /// The name of the authenticationScheme. /// The scheme or null if not found. - Task GetSchemeAsync(string name); + Task GetSchemeAsync(string name); /// /// Returns the scheme that will be used by default for . @@ -31,7 +31,7 @@ namespace Microsoft.AspNetCore.Authentication /// Otherwise, this will fallback to . /// /// The scheme that will be used by default for . - Task GetDefaultAuthenticateSchemeAsync(); + Task GetDefaultAuthenticateSchemeAsync(); /// /// Returns the scheme that will be used by default for . @@ -39,7 +39,7 @@ namespace Microsoft.AspNetCore.Authentication /// Otherwise, this will fallback to . /// /// The scheme that will be used by default for . - Task GetDefaultChallengeSchemeAsync(); + Task GetDefaultChallengeSchemeAsync(); /// /// Returns the scheme that will be used by default for . @@ -47,7 +47,7 @@ namespace Microsoft.AspNetCore.Authentication /// Otherwise, this will fallback to . /// /// The scheme that will be used by default for . - Task GetDefaultForbidSchemeAsync(); + Task GetDefaultForbidSchemeAsync(); /// /// Returns the scheme that will be used by default for . @@ -55,7 +55,7 @@ namespace Microsoft.AspNetCore.Authentication /// Otherwise, this will fallback to . /// /// The scheme that will be used by default for . - Task GetDefaultSignInSchemeAsync(); + Task GetDefaultSignInSchemeAsync(); /// /// Returns the scheme that will be used by default for . @@ -63,7 +63,7 @@ namespace Microsoft.AspNetCore.Authentication /// Otherwise, this will fallback to . /// /// The scheme that will be used by default for . - Task GetDefaultSignOutSchemeAsync(); + Task GetDefaultSignOutSchemeAsync(); /// /// Registers a scheme for use by . @@ -100,4 +100,4 @@ namespace Microsoft.AspNetCore.Authentication /// The schemes in priority order for request handling Task> GetRequestHandlerSchemesAsync(); } -} \ No newline at end of file +} diff --git a/src/Http/Authentication.Abstractions/src/IAuthenticationService.cs b/src/Http/Authentication.Abstractions/src/IAuthenticationService.cs index e5d5336016..ab32aee2ef 100644 --- a/src/Http/Authentication.Abstractions/src/IAuthenticationService.cs +++ b/src/Http/Authentication.Abstractions/src/IAuthenticationService.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Authentication /// The . /// The name of the authentication scheme. /// The result. - Task AuthenticateAsync(HttpContext context, string scheme); + Task AuthenticateAsync(HttpContext context, string? scheme); /// /// Challenge the specified authentication scheme. @@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Authentication /// The name of the authentication scheme. /// The . /// A task. - Task ChallengeAsync(HttpContext context, string scheme, AuthenticationProperties properties); + Task ChallengeAsync(HttpContext context, string? scheme, AuthenticationProperties? properties); /// /// Forbids the specified authentication scheme. @@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.Authentication /// The name of the authentication scheme. /// The . /// A task. - Task ForbidAsync(HttpContext context, string scheme, AuthenticationProperties properties); + Task ForbidAsync(HttpContext context, string? scheme, AuthenticationProperties? properties); /// /// Sign a principal in for the specified authentication scheme. @@ -46,7 +46,7 @@ namespace Microsoft.AspNetCore.Authentication /// The to sign in. /// The . /// A task. - Task SignInAsync(HttpContext context, string scheme, ClaimsPrincipal principal, AuthenticationProperties properties); + Task SignInAsync(HttpContext context, string? scheme, ClaimsPrincipal principal, AuthenticationProperties? properties); /// /// Sign out the specified authentication scheme. @@ -55,6 +55,6 @@ namespace Microsoft.AspNetCore.Authentication /// The name of the authentication scheme. /// The . /// A task. - Task SignOutAsync(HttpContext context, string scheme, AuthenticationProperties properties); + Task SignOutAsync(HttpContext context, string? scheme, AuthenticationProperties? properties); } } diff --git a/src/Http/Authentication.Abstractions/src/IAuthenticationSignInHandler.cs b/src/Http/Authentication.Abstractions/src/IAuthenticationSignInHandler.cs index 69b88032d5..753434cf47 100644 --- a/src/Http/Authentication.Abstractions/src/IAuthenticationSignInHandler.cs +++ b/src/Http/Authentication.Abstractions/src/IAuthenticationSignInHandler.cs @@ -17,6 +17,6 @@ namespace Microsoft.AspNetCore.Authentication /// The user. /// The that contains the extra meta-data arriving with the authentication. /// A task. - Task SignInAsync(ClaimsPrincipal user, AuthenticationProperties properties); + Task SignInAsync(ClaimsPrincipal user, AuthenticationProperties? properties); } } diff --git a/src/Http/Authentication.Abstractions/src/IAuthenticationSignOutHandler.cs b/src/Http/Authentication.Abstractions/src/IAuthenticationSignOutHandler.cs index f76d116a76..b6866308aa 100644 --- a/src/Http/Authentication.Abstractions/src/IAuthenticationSignOutHandler.cs +++ b/src/Http/Authentication.Abstractions/src/IAuthenticationSignOutHandler.cs @@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Authentication /// /// The that contains the extra meta-data arriving with the authentication. /// A task. - Task SignOutAsync(AuthenticationProperties properties); + Task SignOutAsync(AuthenticationProperties? properties); } } diff --git a/src/Http/Authentication.Abstractions/src/Microsoft.AspNetCore.Authentication.Abstractions.csproj b/src/Http/Authentication.Abstractions/src/Microsoft.AspNetCore.Authentication.Abstractions.csproj index 999e6741e5..8b0198fee6 100644 --- a/src/Http/Authentication.Abstractions/src/Microsoft.AspNetCore.Authentication.Abstractions.csproj +++ b/src/Http/Authentication.Abstractions/src/Microsoft.AspNetCore.Authentication.Abstractions.csproj @@ -1,4 +1,4 @@ - + ASP.NET Core common types used by the various authentication components. $(DefaultNetCoreTargetFramework) @@ -7,6 +7,8 @@ true aspnetcore;authentication;security false + enable + Preview diff --git a/src/Http/Authentication.Abstractions/src/TokenExtensions.cs b/src/Http/Authentication.Abstractions/src/TokenExtensions.cs index 128b0651d1..0a04ae9aa3 100644 --- a/src/Http/Authentication.Abstractions/src/TokenExtensions.cs +++ b/src/Http/Authentication.Abstractions/src/TokenExtensions.cs @@ -43,9 +43,14 @@ namespace Microsoft.AspNetCore.Authentication var tokenNames = new List(); foreach (var token in tokens) { + if (token.Name is null) + { + throw new ArgumentNullException(nameof(tokens), "Token name cannot be null."); + } + // REVIEW: should probably check that there are no ; in the token name and throw or encode tokenNames.Add(token.Name); - properties.Items[TokenKeyPrefix+token.Name] = token.Value; + properties.Items[TokenKeyPrefix + token.Name] = token.Value; } if (tokenNames.Count > 0) { @@ -59,7 +64,7 @@ namespace Microsoft.AspNetCore.Authentication /// The properties. /// The token name. /// The token value. - public static string GetTokenValue(this AuthenticationProperties properties, string tokenName) + public static string? GetTokenValue(this AuthenticationProperties properties, string tokenName) { if (properties == null) { @@ -109,9 +114,9 @@ namespace Microsoft.AspNetCore.Authentication } var tokens = new List(); - if (properties.Items.ContainsKey(TokenNamesKey)) + if (properties.Items.TryGetValue(TokenNamesKey, out var value) && !string.IsNullOrEmpty(value)) { - var tokenNames = properties.Items[TokenNamesKey].Split(';'); + var tokenNames = value.Split(';'); foreach (var name in tokenNames) { var token = properties.GetTokenValue(name); @@ -132,7 +137,7 @@ namespace Microsoft.AspNetCore.Authentication /// The context. /// The name of the token. /// The value of the token. - public static Task GetTokenAsync(this IAuthenticationService auth, HttpContext context, string tokenName) + public static Task GetTokenAsync(this IAuthenticationService auth, HttpContext context, string tokenName) => auth.GetTokenAsync(context, scheme: null, tokenName: tokenName); /// @@ -143,7 +148,7 @@ namespace Microsoft.AspNetCore.Authentication /// The name of the authentication scheme. /// The name of the token. /// The value of the token. - public static async Task GetTokenAsync(this IAuthenticationService auth, HttpContext context, string scheme, string tokenName) + public static async Task GetTokenAsync(this IAuthenticationService auth, HttpContext context, string? scheme, string tokenName) { if (auth == null) { @@ -158,4 +163,4 @@ namespace Microsoft.AspNetCore.Authentication return result?.Properties?.GetTokenValue(tokenName); } } -} \ No newline at end of file +} diff --git a/src/Http/Authentication.Core/ref/Microsoft.AspNetCore.Authentication.Core.csproj b/src/Http/Authentication.Core/ref/Microsoft.AspNetCore.Authentication.Core.csproj index 8b59d41a67..ee63b7ae96 100644 --- a/src/Http/Authentication.Core/ref/Microsoft.AspNetCore.Authentication.Core.csproj +++ b/src/Http/Authentication.Core/ref/Microsoft.AspNetCore.Authentication.Core.csproj @@ -2,6 +2,7 @@ $(DefaultNetCoreTargetFramework) + annotations diff --git a/src/Http/Authentication.Core/ref/Microsoft.AspNetCore.Authentication.Core.netcoreapp.cs b/src/Http/Authentication.Core/ref/Microsoft.AspNetCore.Authentication.Core.netcoreapp.cs index 590d651d41..ae1807281f 100644 --- a/src/Http/Authentication.Core/ref/Microsoft.AspNetCore.Authentication.Core.netcoreapp.cs +++ b/src/Http/Authentication.Core/ref/Microsoft.AspNetCore.Authentication.Core.netcoreapp.cs @@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Authentication public AuthenticationHandlerProvider(Microsoft.AspNetCore.Authentication.IAuthenticationSchemeProvider schemes) { } public Microsoft.AspNetCore.Authentication.IAuthenticationSchemeProvider Schemes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } [System.Diagnostics.DebuggerStepThroughAttribute] - public System.Threading.Tasks.Task GetHandlerAsync(Microsoft.AspNetCore.Http.HttpContext context, string authenticationScheme) { throw null; } + public System.Threading.Tasks.Task GetHandlerAsync(Microsoft.AspNetCore.Http.HttpContext context, string authenticationScheme) { throw null; } } public partial class AuthenticationSchemeProvider : Microsoft.AspNetCore.Authentication.IAuthenticationSchemeProvider { @@ -22,13 +22,13 @@ namespace Microsoft.AspNetCore.Authentication protected AuthenticationSchemeProvider(Microsoft.Extensions.Options.IOptions options, System.Collections.Generic.IDictionary schemes) { } public virtual void AddScheme(Microsoft.AspNetCore.Authentication.AuthenticationScheme scheme) { } public virtual System.Threading.Tasks.Task> GetAllSchemesAsync() { throw null; } - public virtual System.Threading.Tasks.Task GetDefaultAuthenticateSchemeAsync() { throw null; } - public virtual System.Threading.Tasks.Task GetDefaultChallengeSchemeAsync() { throw null; } - public virtual System.Threading.Tasks.Task GetDefaultForbidSchemeAsync() { throw null; } - public virtual System.Threading.Tasks.Task GetDefaultSignInSchemeAsync() { throw null; } - public virtual System.Threading.Tasks.Task GetDefaultSignOutSchemeAsync() { throw null; } + public virtual System.Threading.Tasks.Task GetDefaultAuthenticateSchemeAsync() { throw null; } + public virtual System.Threading.Tasks.Task GetDefaultChallengeSchemeAsync() { throw null; } + public virtual System.Threading.Tasks.Task GetDefaultForbidSchemeAsync() { throw null; } + public virtual System.Threading.Tasks.Task GetDefaultSignInSchemeAsync() { throw null; } + public virtual System.Threading.Tasks.Task GetDefaultSignOutSchemeAsync() { throw null; } public virtual System.Threading.Tasks.Task> GetRequestHandlerSchemesAsync() { throw null; } - public virtual System.Threading.Tasks.Task GetSchemeAsync(string name) { throw null; } + public virtual System.Threading.Tasks.Task GetSchemeAsync(string name) { throw null; } public virtual void RemoveScheme(string name) { } public virtual bool TryAddScheme(Microsoft.AspNetCore.Authentication.AuthenticationScheme scheme) { throw null; } } @@ -40,15 +40,15 @@ namespace Microsoft.AspNetCore.Authentication public Microsoft.AspNetCore.Authentication.IAuthenticationSchemeProvider Schemes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } public Microsoft.AspNetCore.Authentication.IClaimsTransformation Transform { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } [System.Diagnostics.DebuggerStepThroughAttribute] - public virtual System.Threading.Tasks.Task AuthenticateAsync(Microsoft.AspNetCore.Http.HttpContext context, string scheme) { throw null; } + public virtual System.Threading.Tasks.Task AuthenticateAsync(Microsoft.AspNetCore.Http.HttpContext context, string? scheme) { throw null; } [System.Diagnostics.DebuggerStepThroughAttribute] - public virtual System.Threading.Tasks.Task ChallengeAsync(Microsoft.AspNetCore.Http.HttpContext context, string scheme, Microsoft.AspNetCore.Authentication.AuthenticationProperties properties) { throw null; } + public virtual System.Threading.Tasks.Task ChallengeAsync(Microsoft.AspNetCore.Http.HttpContext context, string? scheme, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) { throw null; } [System.Diagnostics.DebuggerStepThroughAttribute] - public virtual System.Threading.Tasks.Task ForbidAsync(Microsoft.AspNetCore.Http.HttpContext context, string scheme, Microsoft.AspNetCore.Authentication.AuthenticationProperties properties) { throw null; } + public virtual System.Threading.Tasks.Task ForbidAsync(Microsoft.AspNetCore.Http.HttpContext context, string? scheme, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) { throw null; } [System.Diagnostics.DebuggerStepThroughAttribute] - public virtual System.Threading.Tasks.Task SignInAsync(Microsoft.AspNetCore.Http.HttpContext context, string scheme, System.Security.Claims.ClaimsPrincipal principal, Microsoft.AspNetCore.Authentication.AuthenticationProperties properties) { throw null; } + public virtual System.Threading.Tasks.Task SignInAsync(Microsoft.AspNetCore.Http.HttpContext context, string? scheme, System.Security.Claims.ClaimsPrincipal principal, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) { throw null; } [System.Diagnostics.DebuggerStepThroughAttribute] - public virtual System.Threading.Tasks.Task SignOutAsync(Microsoft.AspNetCore.Http.HttpContext context, string scheme, Microsoft.AspNetCore.Authentication.AuthenticationProperties properties) { throw null; } + public virtual System.Threading.Tasks.Task SignOutAsync(Microsoft.AspNetCore.Http.HttpContext context, string? scheme, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) { throw null; } } public partial class NoopClaimsTransformation : Microsoft.AspNetCore.Authentication.IClaimsTransformation { diff --git a/src/Http/Authentication.Core/src/AuthenticationHandlerProvider.cs b/src/Http/Authentication.Core/src/AuthenticationHandlerProvider.cs index c4921e5334..7441ace718 100644 --- a/src/Http/Authentication.Core/src/AuthenticationHandlerProvider.cs +++ b/src/Http/Authentication.Core/src/AuthenticationHandlerProvider.cs @@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.Authentication public IAuthenticationSchemeProvider Schemes { get; } // handler instance cache, need to initialize once per request - private Dictionary _handlerMap = new Dictionary(StringComparer.Ordinal); + private readonly Dictionary _handlerMap = new Dictionary(StringComparer.Ordinal); /// /// Returns the handler instance that will be used. @@ -37,11 +37,11 @@ namespace Microsoft.AspNetCore.Authentication /// The context. /// The name of the authentication scheme being handled. /// The handler instance. - public async Task GetHandlerAsync(HttpContext context, string authenticationScheme) + public async Task GetHandlerAsync(HttpContext context, string authenticationScheme) { - if (_handlerMap.ContainsKey(authenticationScheme)) + if (_handlerMap.TryGetValue(authenticationScheme, out var value)) { - return _handlerMap[authenticationScheme]; + return value; } var scheme = await Schemes.GetSchemeAsync(authenticationScheme); diff --git a/src/Http/Authentication.Core/src/AuthenticationSchemeProvider.cs b/src/Http/Authentication.Core/src/AuthenticationSchemeProvider.cs index 4f181081f2..d9adda97d1 100644 --- a/src/Http/Authentication.Core/src/AuthenticationSchemeProvider.cs +++ b/src/Http/Authentication.Core/src/AuthenticationSchemeProvider.cs @@ -54,10 +54,10 @@ namespace Microsoft.AspNetCore.Authentication private IEnumerable _schemesCopy = Array.Empty(); private IEnumerable _requestHandlersCopy = Array.Empty(); - private Task GetDefaultSchemeAsync() + private Task GetDefaultSchemeAsync() => _options.DefaultScheme != null ? GetSchemeAsync(_options.DefaultScheme) - : Task.FromResult(null); + : Task.FromResult(null); /// /// Returns the scheme that will be used by default for . @@ -65,7 +65,7 @@ namespace Microsoft.AspNetCore.Authentication /// Otherwise, this will fallback to . /// /// The scheme that will be used by default for . - public virtual Task GetDefaultAuthenticateSchemeAsync() + public virtual Task GetDefaultAuthenticateSchemeAsync() => _options.DefaultAuthenticateScheme != null ? GetSchemeAsync(_options.DefaultAuthenticateScheme) : GetDefaultSchemeAsync(); @@ -76,7 +76,7 @@ namespace Microsoft.AspNetCore.Authentication /// Otherwise, this will fallback to . /// /// The scheme that will be used by default for . - public virtual Task GetDefaultChallengeSchemeAsync() + public virtual Task GetDefaultChallengeSchemeAsync() => _options.DefaultChallengeScheme != null ? GetSchemeAsync(_options.DefaultChallengeScheme) : GetDefaultSchemeAsync(); @@ -87,7 +87,7 @@ namespace Microsoft.AspNetCore.Authentication /// Otherwise, this will fallback to . /// /// The scheme that will be used by default for . - public virtual Task GetDefaultForbidSchemeAsync() + public virtual Task GetDefaultForbidSchemeAsync() => _options.DefaultForbidScheme != null ? GetSchemeAsync(_options.DefaultForbidScheme) : GetDefaultChallengeSchemeAsync(); @@ -98,7 +98,7 @@ namespace Microsoft.AspNetCore.Authentication /// Otherwise, this will fallback to . /// /// The scheme that will be used by default for . - public virtual Task GetDefaultSignInSchemeAsync() + public virtual Task GetDefaultSignInSchemeAsync() => _options.DefaultSignInScheme != null ? GetSchemeAsync(_options.DefaultSignInScheme) : GetDefaultSchemeAsync(); @@ -109,7 +109,7 @@ namespace Microsoft.AspNetCore.Authentication /// Otherwise this will fallback to if that supports sign out. /// /// The scheme that will be used by default for . - public virtual Task GetDefaultSignOutSchemeAsync() + public virtual Task GetDefaultSignOutSchemeAsync() => _options.DefaultSignOutScheme != null ? GetSchemeAsync(_options.DefaultSignOutScheme) : GetDefaultSignInSchemeAsync(); @@ -119,7 +119,7 @@ namespace Microsoft.AspNetCore.Authentication /// /// The name of the authenticationScheme. /// The scheme or null if not found. - public virtual Task GetSchemeAsync(string name) + public virtual Task GetSchemeAsync(string name) => Task.FromResult(_schemes.ContainsKey(name) ? _schemes[name] : null); /// @@ -204,4 +204,4 @@ namespace Microsoft.AspNetCore.Authentication public virtual Task> GetAllSchemesAsync() => Task.FromResult(_schemesCopy); } -} \ No newline at end of file +} diff --git a/src/Http/Authentication.Core/src/AuthenticationService.cs b/src/Http/Authentication.Core/src/AuthenticationService.cs index de63980c4a..56172f1739 100644 --- a/src/Http/Authentication.Core/src/AuthenticationService.cs +++ b/src/Http/Authentication.Core/src/AuthenticationService.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Authentication /// public class AuthenticationService : IAuthenticationService { - private HashSet _transformCache; + private HashSet? _transformCache; /// /// Constructor. @@ -59,7 +59,7 @@ namespace Microsoft.AspNetCore.Authentication /// The . /// The name of the authentication scheme. /// The result. - public virtual async Task AuthenticateAsync(HttpContext context, string scheme) + public virtual async Task AuthenticateAsync(HttpContext context, string? scheme) { if (scheme == null) { @@ -80,7 +80,7 @@ namespace Microsoft.AspNetCore.Authentication var result = await handler.AuthenticateAsync(); if (result != null && result.Succeeded) { - var principal = result.Principal; + var principal = result.Principal!; var doTransform = true; _transformCache ??= new HashSet(); if (_transformCache.Contains(principal)) @@ -93,7 +93,7 @@ namespace Microsoft.AspNetCore.Authentication principal = await Transform.TransformAsync(principal); _transformCache.Add(principal); } - return AuthenticateResult.Success(new AuthenticationTicket(principal, result.Properties, result.Ticket.AuthenticationScheme)); + return AuthenticateResult.Success(new AuthenticationTicket(principal, result.Properties, result.Ticket!.AuthenticationScheme)); } return result; } @@ -105,7 +105,7 @@ namespace Microsoft.AspNetCore.Authentication /// The name of the authentication scheme. /// The . /// A task. - public virtual async Task ChallengeAsync(HttpContext context, string scheme, AuthenticationProperties properties) + public virtual async Task ChallengeAsync(HttpContext context, string? scheme, AuthenticationProperties? properties) { if (scheme == null) { @@ -133,7 +133,7 @@ namespace Microsoft.AspNetCore.Authentication /// The name of the authentication scheme. /// The . /// A task. - public virtual async Task ForbidAsync(HttpContext context, string scheme, AuthenticationProperties properties) + public virtual async Task ForbidAsync(HttpContext context, string? scheme, AuthenticationProperties? properties) { if (scheme == null) { @@ -162,7 +162,7 @@ namespace Microsoft.AspNetCore.Authentication /// The to sign in. /// The . /// A task. - public virtual async Task SignInAsync(HttpContext context, string scheme, ClaimsPrincipal principal, AuthenticationProperties properties) + public virtual async Task SignInAsync(HttpContext context, string? scheme, ClaimsPrincipal principal, AuthenticationProperties? properties) { if (principal == null) { @@ -213,7 +213,7 @@ namespace Microsoft.AspNetCore.Authentication /// The name of the authentication scheme. /// The . /// A task. - public virtual async Task SignOutAsync(HttpContext context, string scheme, AuthenticationProperties properties) + public virtual async Task SignOutAsync(HttpContext context, string? scheme, AuthenticationProperties? properties) { if (scheme == null) { diff --git a/src/Http/Authentication.Core/src/Microsoft.AspNetCore.Authentication.Core.csproj b/src/Http/Authentication.Core/src/Microsoft.AspNetCore.Authentication.Core.csproj index f3bc6965ea..e139c7a973 100644 --- a/src/Http/Authentication.Core/src/Microsoft.AspNetCore.Authentication.Core.csproj +++ b/src/Http/Authentication.Core/src/Microsoft.AspNetCore.Authentication.Core.csproj @@ -8,6 +8,7 @@ true aspnetcore;authentication;security false + enable diff --git a/src/Http/Authentication.Core/test/AuthenticationPropertiesTests.cs b/src/Http/Authentication.Core/test/AuthenticationPropertiesTests.cs index cb7dbeb95f..5e44974c56 100644 --- a/src/Http/Authentication.Core/test/AuthenticationPropertiesTests.cs +++ b/src/Http/Authentication.Core/test/AuthenticationPropertiesTests.cs @@ -46,7 +46,7 @@ namespace Microsoft.AspNetCore.Authentication.Core.Test [Fact] public void ItemsConstructor_ReusesItemsDictionary() { - var items = new Dictionary + var items = new Dictionary { ["foo"] = "bar", }; @@ -58,11 +58,11 @@ namespace Microsoft.AspNetCore.Authentication.Core.Test [Fact] public void FullConstructor_ReusesDictionaries() { - var items = new Dictionary + var items = new Dictionary { ["foo"] = "bar", }; - var parameters = new Dictionary + var parameters = new Dictionary { ["number"] = 1234, ["list"] = new List { "a", "b", "c" }, @@ -119,7 +119,7 @@ namespace Microsoft.AspNetCore.Authentication.Core.Test Assert.Equal("foo bar", props.Parameters["foo"]); Assert.Equal(1, props.Parameters.Count); - props.SetParameter("foo", null); + props.SetParameter("foo", null); Assert.Null(props.GetParameter("foo")); Assert.Null(props.Parameters["foo"]); Assert.Equal(1, props.Parameters.Count); @@ -156,7 +156,7 @@ namespace Microsoft.AspNetCore.Authentication.Core.Test Assert.Same(list, props.Parameters["foo"]); Assert.Equal(1, props.Parameters.Count); - props.SetParameter>("foo", null); + props.SetParameter?>("foo", null); Assert.Null(props.GetParameter>("foo")); Assert.Null(props.Parameters["foo"]); Assert.Equal(1, props.Parameters.Count); diff --git a/src/Http/Authentication.Core/test/AuthenticationSchemeProviderTests.cs b/src/Http/Authentication.Core/test/AuthenticationSchemeProviderTests.cs index f422ee885d..d60cd58a7b 100644 --- a/src/Http/Authentication.Core/test/AuthenticationSchemeProviderTests.cs +++ b/src/Http/Authentication.Core/test/AuthenticationSchemeProviderTests.cs @@ -41,11 +41,11 @@ namespace Microsoft.AspNetCore.Authentication.Core.Test }).BuildServiceProvider(); var provider = services.GetRequiredService(); - Assert.Equal("B", (await provider.GetDefaultForbidSchemeAsync()).Name); - Assert.Equal("B", (await provider.GetDefaultAuthenticateSchemeAsync()).Name); - Assert.Equal("B", (await provider.GetDefaultChallengeSchemeAsync()).Name); - Assert.Equal("B", (await provider.GetDefaultSignInSchemeAsync()).Name); - Assert.Equal("B", (await provider.GetDefaultSignOutSchemeAsync()).Name); + Assert.Equal("B", (await provider.GetDefaultForbidSchemeAsync())!.Name); + Assert.Equal("B", (await provider.GetDefaultAuthenticateSchemeAsync())!.Name); + Assert.Equal("B", (await provider.GetDefaultChallengeSchemeAsync())!.Name); + Assert.Equal("B", (await provider.GetDefaultSignInSchemeAsync())!.Name); + Assert.Equal("B", (await provider.GetDefaultSignOutSchemeAsync())!.Name); } @@ -62,7 +62,7 @@ namespace Microsoft.AspNetCore.Authentication.Core.Test var provider = services.GetRequiredService(); var scheme = await provider.GetDefaultSignOutSchemeAsync(); Assert.NotNull(scheme); - Assert.Equal("signin", scheme.Name); + Assert.Equal("signin", scheme!.Name); } [Fact] @@ -78,7 +78,7 @@ namespace Microsoft.AspNetCore.Authentication.Core.Test var provider = services.GetRequiredService(); var scheme = await provider.GetDefaultForbidSchemeAsync(); Assert.NotNull(scheme); - Assert.Equal("challenge", scheme.Name); + Assert.Equal("challenge", scheme!.Name); } [Fact] @@ -99,11 +99,11 @@ namespace Microsoft.AspNetCore.Authentication.Core.Test }).BuildServiceProvider(); var provider = services.GetRequiredService(); - Assert.Equal("B", (await provider.GetDefaultForbidSchemeAsync()).Name); - Assert.Equal("C", (await provider.GetDefaultAuthenticateSchemeAsync()).Name); - Assert.Equal("A", (await provider.GetDefaultChallengeSchemeAsync()).Name); - Assert.Equal("C", (await provider.GetDefaultSignInSchemeAsync()).Name); - Assert.Equal("A", (await provider.GetDefaultSignOutSchemeAsync()).Name); + Assert.Equal("B", (await provider.GetDefaultForbidSchemeAsync())!.Name); + Assert.Equal("C", (await provider.GetDefaultAuthenticateSchemeAsync())!.Name); + Assert.Equal("A", (await provider.GetDefaultChallengeSchemeAsync())!.Name); + Assert.Equal("C", (await provider.GetDefaultSignInSchemeAsync())!.Name); + Assert.Equal("A", (await provider.GetDefaultSignOutSchemeAsync())!.Name); } [Fact] @@ -176,12 +176,12 @@ namespace Microsoft.AspNetCore.Authentication.Core.Test throw new NotImplementedException(); } - public Task ChallengeAsync(AuthenticationProperties properties) + public Task ChallengeAsync(AuthenticationProperties? properties) { throw new NotImplementedException(); } - public Task ForbidAsync(AuthenticationProperties properties) + public Task ForbidAsync(AuthenticationProperties? properties) { throw new NotImplementedException(); } @@ -194,12 +194,12 @@ namespace Microsoft.AspNetCore.Authentication.Core.Test private class SignInHandler : Handler, IAuthenticationSignInHandler { - public Task SignInAsync(ClaimsPrincipal user, AuthenticationProperties properties) + public Task SignInAsync(ClaimsPrincipal user, AuthenticationProperties? properties) { throw new NotImplementedException(); } - public Task SignOutAsync(AuthenticationProperties properties) + public Task SignOutAsync(AuthenticationProperties? properties) { throw new NotImplementedException(); } @@ -207,7 +207,7 @@ namespace Microsoft.AspNetCore.Authentication.Core.Test private class SignOutHandler : Handler, IAuthenticationSignOutHandler { - public Task SignOutAsync(AuthenticationProperties properties) + public Task SignOutAsync(AuthenticationProperties? properties) { throw new NotImplementedException(); } diff --git a/src/Http/Authentication.Core/test/AuthenticationServiceTests.cs b/src/Http/Authentication.Core/test/AuthenticationServiceTests.cs index 6134ca9172..6f0045f225 100644 --- a/src/Http/Authentication.Core/test/AuthenticationServiceTests.cs +++ b/src/Http/Authentication.Core/test/AuthenticationServiceTests.cs @@ -264,12 +264,12 @@ namespace Microsoft.AspNetCore.Authentication.Core.Test "whatever"))); } - public Task ChallengeAsync(AuthenticationProperties properties) + public Task ChallengeAsync(AuthenticationProperties? properties) { return Task.FromResult(0); } - public Task ForbidAsync(AuthenticationProperties properties) + public Task ForbidAsync(AuthenticationProperties? properties) { return Task.FromResult(0); } @@ -287,12 +287,12 @@ namespace Microsoft.AspNetCore.Authentication.Core.Test return Task.FromResult(AuthenticateResult.NoResult()); } - public Task ChallengeAsync(AuthenticationProperties properties) + public Task ChallengeAsync(AuthenticationProperties? properties) { return Task.FromResult(0); } - public Task ForbidAsync(AuthenticationProperties properties) + public Task ForbidAsync(AuthenticationProperties? properties) { return Task.FromResult(0); } @@ -302,12 +302,12 @@ namespace Microsoft.AspNetCore.Authentication.Core.Test return Task.FromResult(0); } - public Task SignInAsync(ClaimsPrincipal user, AuthenticationProperties properties) + public Task SignInAsync(ClaimsPrincipal user, AuthenticationProperties? properties) { return Task.FromResult(0); } - public Task SignOutAsync(AuthenticationProperties properties) + public Task SignOutAsync(AuthenticationProperties? properties) { return Task.FromResult(0); } @@ -320,12 +320,12 @@ namespace Microsoft.AspNetCore.Authentication.Core.Test return Task.FromResult(AuthenticateResult.NoResult()); } - public Task ChallengeAsync(AuthenticationProperties properties) + public Task ChallengeAsync(AuthenticationProperties? properties) { return Task.FromResult(0); } - public Task ForbidAsync(AuthenticationProperties properties) + public Task ForbidAsync(AuthenticationProperties? properties) { return Task.FromResult(0); } @@ -335,7 +335,7 @@ namespace Microsoft.AspNetCore.Authentication.Core.Test return Task.FromResult(0); } - public Task SignOutAsync(AuthenticationProperties properties) + public Task SignOutAsync(AuthenticationProperties? properties) { return Task.FromResult(0); } @@ -348,12 +348,12 @@ namespace Microsoft.AspNetCore.Authentication.Core.Test return Task.FromResult(AuthenticateResult.NoResult()); } - public Task ChallengeAsync(AuthenticationProperties properties) + public Task ChallengeAsync(AuthenticationProperties? properties) { return Task.FromResult(0); } - public Task ForbidAsync(AuthenticationProperties properties) + public Task ForbidAsync(AuthenticationProperties? properties) { return Task.FromResult(0); } @@ -368,12 +368,12 @@ namespace Microsoft.AspNetCore.Authentication.Core.Test return Task.FromResult(0); } - public Task SignInAsync(ClaimsPrincipal user, AuthenticationProperties properties) + public Task SignInAsync(ClaimsPrincipal user, AuthenticationProperties? properties) { return Task.FromResult(0); } - public Task SignOutAsync(AuthenticationProperties properties) + public Task SignOutAsync(AuthenticationProperties? properties) { return Task.FromResult(0); } @@ -386,12 +386,12 @@ namespace Microsoft.AspNetCore.Authentication.Core.Test throw new NotImplementedException(); } - public Task ChallengeAsync(AuthenticationProperties properties) + public Task ChallengeAsync(AuthenticationProperties? properties) { throw new NotImplementedException(); } - public Task ForbidAsync(AuthenticationProperties properties) + public Task ForbidAsync(AuthenticationProperties? properties) { return Task.FromResult(0); } @@ -406,12 +406,12 @@ namespace Microsoft.AspNetCore.Authentication.Core.Test return Task.FromResult(0); } - public Task SignInAsync(ClaimsPrincipal user, AuthenticationProperties properties) + public Task SignInAsync(ClaimsPrincipal user, AuthenticationProperties? properties) { throw new NotImplementedException(); } - public Task SignOutAsync(AuthenticationProperties properties) + public Task SignOutAsync(AuthenticationProperties? properties) { throw new NotImplementedException(); } diff --git a/src/Http/Authentication.Core/test/Microsoft.AspNetCore.Authentication.Core.Test.csproj b/src/Http/Authentication.Core/test/Microsoft.AspNetCore.Authentication.Core.Test.csproj index ca55bdd85c..528810eaaa 100644 --- a/src/Http/Authentication.Core/test/Microsoft.AspNetCore.Authentication.Core.Test.csproj +++ b/src/Http/Authentication.Core/test/Microsoft.AspNetCore.Authentication.Core.Test.csproj @@ -2,6 +2,7 @@ $(DefaultNetCoreTargetFramework) + enable diff --git a/src/Http/Authentication.Core/test/TokenExtensionTests.cs b/src/Http/Authentication.Core/test/TokenExtensionTests.cs index 49f47cf45f..639dda2908 100644 --- a/src/Http/Authentication.Core/test/TokenExtensionTests.cs +++ b/src/Http/Authentication.Core/test/TokenExtensionTests.cs @@ -170,12 +170,12 @@ namespace Microsoft.AspNetCore.Authentication.Core.Test return Task.FromResult(AuthenticateResult.Success(new AuthenticationTicket(new ClaimsPrincipal(), props, "simple"))); } - public Task ChallengeAsync(AuthenticationProperties properties) + public Task ChallengeAsync(AuthenticationProperties? properties) { throw new NotImplementedException(); } - public Task ForbidAsync(AuthenticationProperties properties) + public Task ForbidAsync(AuthenticationProperties? properties) { throw new NotImplementedException(); }