Make AuthenticateAsync return non-null result (#22708)

* Make AuthenticateAsync return non-null result

* NoResult
This commit is contained in:
Pranav K 2020-06-09 10:05:26 -07:00 committed by GitHub
parent a27356078f
commit 0794d6077d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 10 deletions

View File

@ -22,8 +22,8 @@ namespace Microsoft.AspNetCore.Authentication
} }
public static partial class AuthenticationHttpContextExtensions public static partial class AuthenticationHttpContextExtensions
{ {
public static System.Threading.Tasks.Task<Microsoft.AspNetCore.Authentication.AuthenticateResult?> AuthenticateAsync(this Microsoft.AspNetCore.Http.HttpContext context) { throw null; } public static System.Threading.Tasks.Task<Microsoft.AspNetCore.Authentication.AuthenticateResult> AuthenticateAsync(this Microsoft.AspNetCore.Http.HttpContext context) { throw null; }
public static System.Threading.Tasks.Task<Microsoft.AspNetCore.Authentication.AuthenticateResult?> AuthenticateAsync(this Microsoft.AspNetCore.Http.HttpContext context, string? scheme) { throw null; } public static System.Threading.Tasks.Task<Microsoft.AspNetCore.Authentication.AuthenticateResult> 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) { 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) { throw null; }
@ -157,7 +157,7 @@ namespace Microsoft.AspNetCore.Authentication
} }
public partial interface IAuthenticationService public partial interface IAuthenticationService
{ {
System.Threading.Tasks.Task<Microsoft.AspNetCore.Authentication.AuthenticateResult?> AuthenticateAsync(Microsoft.AspNetCore.Http.HttpContext context, string? scheme); System.Threading.Tasks.Task<Microsoft.AspNetCore.Authentication.AuthenticateResult> 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 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 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 SignInAsync(Microsoft.AspNetCore.Http.HttpContext context, string? scheme, System.Security.Claims.ClaimsPrincipal principal, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties);

View File

@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Authentication
/// </summary> /// </summary>
/// <param name="context">The <see cref="HttpContext"/> context.</param> /// <param name="context">The <see cref="HttpContext"/> context.</param>
/// <returns>The <see cref="AuthenticateResult"/>.</returns> /// <returns>The <see cref="AuthenticateResult"/>.</returns>
public static Task<AuthenticateResult?> AuthenticateAsync(this HttpContext context) => public static Task<AuthenticateResult> AuthenticateAsync(this HttpContext context) =>
context.AuthenticateAsync(scheme: null); context.AuthenticateAsync(scheme: null);
/// <summary> /// <summary>
@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Authentication
/// <param name="context">The <see cref="HttpContext"/> context.</param> /// <param name="context">The <see cref="HttpContext"/> context.</param>
/// <param name="scheme">The name of the authentication scheme.</param> /// <param name="scheme">The name of the authentication scheme.</param>
/// <returns>The <see cref="AuthenticateResult"/>.</returns> /// <returns>The <see cref="AuthenticateResult"/>.</returns>
public static Task<AuthenticateResult?> AuthenticateAsync(this HttpContext context, string? scheme) => public static Task<AuthenticateResult> AuthenticateAsync(this HttpContext context, string? scheme) =>
context.RequestServices.GetRequiredService<IAuthenticationService>().AuthenticateAsync(context, scheme); context.RequestServices.GetRequiredService<IAuthenticationService>().AuthenticateAsync(context, scheme);
/// <summary> /// <summary>

View File

@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Authentication
/// <param name="context">The <see cref="HttpContext"/>.</param> /// <param name="context">The <see cref="HttpContext"/>.</param>
/// <param name="scheme">The name of the authentication scheme.</param> /// <param name="scheme">The name of the authentication scheme.</param>
/// <returns>The result.</returns> /// <returns>The result.</returns>
Task<AuthenticateResult?> AuthenticateAsync(HttpContext context, string? scheme); Task<AuthenticateResult> AuthenticateAsync(HttpContext context, string? scheme);
/// <summary> /// <summary>
/// Challenge the specified authentication scheme. /// Challenge the specified authentication scheme.

View File

@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Authentication
public Microsoft.AspNetCore.Authentication.IAuthenticationSchemeProvider Schemes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } 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; } } public Microsoft.AspNetCore.Authentication.IClaimsTransformation Transform { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
[System.Diagnostics.DebuggerStepThroughAttribute] [System.Diagnostics.DebuggerStepThroughAttribute]
public virtual System.Threading.Tasks.Task<Microsoft.AspNetCore.Authentication.AuthenticateResult?> AuthenticateAsync(Microsoft.AspNetCore.Http.HttpContext context, string? scheme) { throw null; } public virtual System.Threading.Tasks.Task<Microsoft.AspNetCore.Authentication.AuthenticateResult> AuthenticateAsync(Microsoft.AspNetCore.Http.HttpContext context, string? scheme) { throw null; }
[System.Diagnostics.DebuggerStepThroughAttribute] [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] [System.Diagnostics.DebuggerStepThroughAttribute]

View File

@ -59,7 +59,7 @@ namespace Microsoft.AspNetCore.Authentication
/// <param name="context">The <see cref="HttpContext"/>.</param> /// <param name="context">The <see cref="HttpContext"/>.</param>
/// <param name="scheme">The name of the authentication scheme.</param> /// <param name="scheme">The name of the authentication scheme.</param>
/// <returns>The result.</returns> /// <returns>The result.</returns>
public virtual async Task<AuthenticateResult?> AuthenticateAsync(HttpContext context, string? scheme) public virtual async Task<AuthenticateResult> AuthenticateAsync(HttpContext context, string? scheme)
{ {
if (scheme == null) if (scheme == null)
{ {
@ -77,8 +77,10 @@ namespace Microsoft.AspNetCore.Authentication
throw await CreateMissingHandlerException(scheme); throw await CreateMissingHandlerException(scheme);
} }
var result = await handler.AuthenticateAsync(); // Handlers should not return null, but we'll be tolerant of null values for legacy reasons.
if (result != null && result.Succeeded) var result = (await handler.AuthenticateAsync()) ?? AuthenticateResult.NoResult();
if (result.Succeeded)
{ {
var principal = result.Principal!; var principal = result.Principal!;
var doTransform = true; var doTransform = true;