Make AuthenticateAsync return non-null result (#22708)
* Make AuthenticateAsync return non-null result * NoResult
This commit is contained in:
parent
a27356078f
commit
0794d6077d
|
|
@ -22,8 +22,8 @@ namespace Microsoft.AspNetCore.Authentication
|
|||
}
|
||||
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, string? scheme) { 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 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, string scheme) { throw null; }
|
||||
|
|
@ -157,7 +157,7 @@ namespace Microsoft.AspNetCore.Authentication
|
|||
}
|
||||
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 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);
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Authentication
|
|||
/// </summary>
|
||||
/// <param name="context">The <see cref="HttpContext"/> context.</param>
|
||||
/// <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);
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.Authentication
|
|||
/// <param name="context">The <see cref="HttpContext"/> context.</param>
|
||||
/// <param name="scheme">The name of the authentication scheme.</param>
|
||||
/// <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);
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Authentication
|
|||
/// <param name="context">The <see cref="HttpContext"/>.</param>
|
||||
/// <param name="scheme">The name of the authentication scheme.</param>
|
||||
/// <returns>The result.</returns>
|
||||
Task<AuthenticateResult?> AuthenticateAsync(HttpContext context, string? scheme);
|
||||
Task<AuthenticateResult> AuthenticateAsync(HttpContext context, string? scheme);
|
||||
|
||||
/// <summary>
|
||||
/// Challenge the specified authentication scheme.
|
||||
|
|
|
|||
|
|
@ -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.IClaimsTransformation Transform { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
|
||||
[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]
|
||||
public virtual System.Threading.Tasks.Task ChallengeAsync(Microsoft.AspNetCore.Http.HttpContext context, string? scheme, Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties) { throw null; }
|
||||
[System.Diagnostics.DebuggerStepThroughAttribute]
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ namespace Microsoft.AspNetCore.Authentication
|
|||
/// <param name="context">The <see cref="HttpContext"/>.</param>
|
||||
/// <param name="scheme">The name of the authentication scheme.</param>
|
||||
/// <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)
|
||||
{
|
||||
|
|
@ -77,8 +77,10 @@ namespace Microsoft.AspNetCore.Authentication
|
|||
throw await CreateMissingHandlerException(scheme);
|
||||
}
|
||||
|
||||
var result = await handler.AuthenticateAsync();
|
||||
if (result != null && result.Succeeded)
|
||||
// Handlers should not return null, but we'll be tolerant of null values for legacy reasons.
|
||||
var result = (await handler.AuthenticateAsync()) ?? AuthenticateResult.NoResult();
|
||||
|
||||
if (result.Succeeded)
|
||||
{
|
||||
var principal = result.Principal!;
|
||||
var doTransform = true;
|
||||
|
|
|
|||
Loading…
Reference in New Issue