Use TaskCache class from Microsoft.Extensions.TaskCache.Sources (#968)
Instead of Task.FromResult(0)
This commit is contained in:
parent
5b323e5ba1
commit
ce0ed3d237
|
|
@ -4,6 +4,7 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Internal;
|
||||
|
||||
namespace Microsoft.AspNetCore.Authentication.Cookies
|
||||
{
|
||||
|
|
@ -17,22 +18,22 @@ namespace Microsoft.AspNetCore.Authentication.Cookies
|
|||
/// <summary>
|
||||
/// A delegate assigned to this property will be invoked when the related method is called.
|
||||
/// </summary>
|
||||
public Func<CookieValidatePrincipalContext, Task> OnValidatePrincipal { get; set; } = context => Task.FromResult(0);
|
||||
public Func<CookieValidatePrincipalContext, Task> OnValidatePrincipal { get; set; } = context => TaskCache.CompletedTask;
|
||||
|
||||
/// <summary>
|
||||
/// A delegate assigned to this property will be invoked when the related method is called.
|
||||
/// </summary>
|
||||
public Func<CookieSigningInContext, Task> OnSigningIn { get; set; } = context => Task.FromResult(0);
|
||||
public Func<CookieSigningInContext, Task> OnSigningIn { get; set; } = context => TaskCache.CompletedTask;
|
||||
|
||||
/// <summary>
|
||||
/// A delegate assigned to this property will be invoked when the related method is called.
|
||||
/// </summary>
|
||||
public Func<CookieSignedInContext, Task> OnSignedIn { get; set; } = context => Task.FromResult(0);
|
||||
public Func<CookieSignedInContext, Task> OnSignedIn { get; set; } = context => TaskCache.CompletedTask;
|
||||
|
||||
/// <summary>
|
||||
/// A delegate assigned to this property will be invoked when the related method is called.
|
||||
/// </summary>
|
||||
public Func<CookieSigningOutContext, Task> OnSigningOut { get; set; } = context => Task.FromResult(0);
|
||||
public Func<CookieSigningOutContext, Task> OnSigningOut { get; set; } = context => TaskCache.CompletedTask;
|
||||
|
||||
/// <summary>
|
||||
/// A delegate assigned to this property will be invoked when the related method is called.
|
||||
|
|
@ -48,7 +49,7 @@ namespace Microsoft.AspNetCore.Authentication.Cookies
|
|||
{
|
||||
context.Response.Redirect(context.RedirectUri);
|
||||
}
|
||||
return Task.FromResult(0);
|
||||
return TaskCache.CompletedTask;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -65,7 +66,7 @@ namespace Microsoft.AspNetCore.Authentication.Cookies
|
|||
{
|
||||
context.Response.Redirect(context.RedirectUri);
|
||||
}
|
||||
return Task.FromResult(0);
|
||||
return TaskCache.CompletedTask;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -81,7 +82,7 @@ namespace Microsoft.AspNetCore.Authentication.Cookies
|
|||
{
|
||||
context.Response.Redirect(context.RedirectUri);
|
||||
}
|
||||
return Task.FromResult(0);
|
||||
return TaskCache.CompletedTask;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -97,7 +98,7 @@ namespace Microsoft.AspNetCore.Authentication.Cookies
|
|||
{
|
||||
context.Response.Redirect(context.RedirectUri);
|
||||
}
|
||||
return Task.FromResult(0);
|
||||
return TaskCache.CompletedTask;
|
||||
};
|
||||
|
||||
private static bool IsAjaxRequest(HttpRequest request)
|
||||
|
|
|
|||
|
|
@ -23,6 +23,10 @@
|
|||
"dependencies": {
|
||||
"Microsoft.AspNetCore.Authentication": "1.1.0-*",
|
||||
"Microsoft.Extensions.Options": "1.1.0-*",
|
||||
"Microsoft.Extensions.TaskCache.Sources": {
|
||||
"version": "1.1.0-*",
|
||||
"type": "build"
|
||||
},
|
||||
"Microsoft.Extensions.WebEncoders": "1.1.0-*"
|
||||
},
|
||||
"frameworks": {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Internal;
|
||||
|
||||
namespace Microsoft.AspNetCore.Authentication.JwtBearer
|
||||
{
|
||||
|
|
@ -14,22 +15,22 @@ namespace Microsoft.AspNetCore.Authentication.JwtBearer
|
|||
/// <summary>
|
||||
/// Invoked if exceptions are thrown during request processing. The exceptions will be re-thrown after this event unless suppressed.
|
||||
/// </summary>
|
||||
public Func<AuthenticationFailedContext, Task> OnAuthenticationFailed { get; set; } = context => Task.FromResult(0);
|
||||
public Func<AuthenticationFailedContext, Task> OnAuthenticationFailed { get; set; } = context => TaskCache.CompletedTask;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when a protocol message is first received.
|
||||
/// </summary>
|
||||
public Func<MessageReceivedContext, Task> OnMessageReceived { get; set; } = context => Task.FromResult(0);
|
||||
public Func<MessageReceivedContext, Task> OnMessageReceived { get; set; } = context => TaskCache.CompletedTask;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked after the security token has passed validation and a ClaimsIdentity has been generated.
|
||||
/// </summary>
|
||||
public Func<TokenValidatedContext, Task> OnTokenValidated { get; set; } = context => Task.FromResult(0);
|
||||
public Func<TokenValidatedContext, Task> OnTokenValidated { get; set; } = context => TaskCache.CompletedTask;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked before a challenge is sent back to the caller.
|
||||
/// </summary>
|
||||
public Func<JwtBearerChallengeContext, Task> OnChallenge { get; set; } = context => Task.FromResult(0);
|
||||
public Func<JwtBearerChallengeContext, Task> OnChallenge { get; set; } = context => TaskCache.CompletedTask;
|
||||
|
||||
public virtual Task AuthenticationFailed(AuthenticationFailedContext context) => OnAuthenticationFailed(context);
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,10 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"Microsoft.AspNetCore.Authentication": "1.1.0-*",
|
||||
"Microsoft.Extensions.TaskCache.Sources": {
|
||||
"version": "1.1.0-*",
|
||||
"type": "build"
|
||||
},
|
||||
"Microsoft.IdentityModel.Protocols.OpenIdConnect": "2.0.0-*"
|
||||
},
|
||||
"frameworks": {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Internal;
|
||||
|
||||
namespace Microsoft.AspNetCore.Authentication.OAuth
|
||||
{
|
||||
|
|
@ -14,7 +15,7 @@ namespace Microsoft.AspNetCore.Authentication.OAuth
|
|||
/// <summary>
|
||||
/// Gets or sets the function that is invoked when the CreatingTicket method is invoked.
|
||||
/// </summary>
|
||||
public Func<OAuthCreatingTicketContext, Task> OnCreatingTicket { get; set; } = context => Task.FromResult(0);
|
||||
public Func<OAuthCreatingTicketContext, Task> OnCreatingTicket { get; set; } = context => TaskCache.CompletedTask;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the delegate that is invoked when the RedirectToAuthorizationEndpoint method is invoked.
|
||||
|
|
@ -22,7 +23,7 @@ namespace Microsoft.AspNetCore.Authentication.OAuth
|
|||
public Func<OAuthRedirectToAuthorizationContext, Task> OnRedirectToAuthorizationEndpoint { get; set; } = context =>
|
||||
{
|
||||
context.Response.Redirect(context.RedirectUri);
|
||||
return Task.FromResult(0);
|
||||
return TaskCache.CompletedTask;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -22,6 +22,10 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"Microsoft.AspNetCore.Authentication": "1.1.0-*",
|
||||
"Microsoft.Extensions.TaskCache.Sources": {
|
||||
"version": "1.1.0-*",
|
||||
"type": "build"
|
||||
},
|
||||
"Newtonsoft.Json": "9.0.1"
|
||||
},
|
||||
"frameworks": {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Internal;
|
||||
|
||||
namespace Microsoft.AspNetCore.Authentication.OpenIdConnect
|
||||
{
|
||||
|
|
@ -14,47 +15,47 @@ namespace Microsoft.AspNetCore.Authentication.OpenIdConnect
|
|||
/// <summary>
|
||||
/// Invoked if exceptions are thrown during request processing. The exceptions will be re-thrown after this event unless suppressed.
|
||||
/// </summary>
|
||||
public Func<AuthenticationFailedContext, Task> OnAuthenticationFailed { get; set; } = context => Task.FromResult(0);
|
||||
public Func<AuthenticationFailedContext, Task> OnAuthenticationFailed { get; set; } = context => TaskCache.CompletedTask;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked after security token validation if an authorization code is present in the protocol message.
|
||||
/// </summary>
|
||||
public Func<AuthorizationCodeReceivedContext, Task> OnAuthorizationCodeReceived { get; set; } = context => Task.FromResult(0);
|
||||
public Func<AuthorizationCodeReceivedContext, Task> OnAuthorizationCodeReceived { get; set; } = context => TaskCache.CompletedTask;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when a protocol message is first received.
|
||||
/// </summary>
|
||||
public Func<MessageReceivedContext, Task> OnMessageReceived { get; set; } = context => Task.FromResult(0);
|
||||
public Func<MessageReceivedContext, Task> OnMessageReceived { get; set; } = context => TaskCache.CompletedTask;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked before redirecting to the identity provider to authenticate.
|
||||
/// </summary>
|
||||
public Func<RedirectContext, Task> OnRedirectToIdentityProvider { get; set; } = context => Task.FromResult(0);
|
||||
public Func<RedirectContext, Task> OnRedirectToIdentityProvider { get; set; } = context => TaskCache.CompletedTask;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked before redirecting to the identity provider to sign out.
|
||||
/// </summary>
|
||||
public Func<RedirectContext, Task> OnRedirectToIdentityProviderForSignOut { get; set; } = context => Task.FromResult(0);
|
||||
public Func<RedirectContext, Task> OnRedirectToIdentityProviderForSignOut { get; set; } = context => TaskCache.CompletedTask;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when a request is received on the RemoteSignOutPath.
|
||||
/// </summary>
|
||||
public Func<RemoteSignOutContext, Task> OnRemoteSignOut { get; set; } = context => Task.FromResult(0);
|
||||
public Func<RemoteSignOutContext, Task> OnRemoteSignOut { get; set; } = context => TaskCache.CompletedTask;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked after "authorization code" is redeemed for tokens at the token endpoint.
|
||||
/// </summary>
|
||||
public Func<TokenResponseReceivedContext, Task> OnTokenResponseReceived { get; set; } = context => Task.FromResult(0);
|
||||
public Func<TokenResponseReceivedContext, Task> OnTokenResponseReceived { get; set; } = context => TaskCache.CompletedTask;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when an IdToken has been validated and produced an AuthenticationTicket.
|
||||
/// </summary>
|
||||
public Func<TokenValidatedContext, Task> OnTokenValidated { get; set; } = context => Task.FromResult(0);
|
||||
public Func<TokenValidatedContext, Task> OnTokenValidated { get; set; } = context => TaskCache.CompletedTask;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when user information is retrieved from the UserInfoEndpoint.
|
||||
/// </summary>
|
||||
public Func<UserInformationReceivedContext, Task> OnUserInformationReceived { get; set; } = context => Task.FromResult(0);
|
||||
public Func<UserInformationReceivedContext, Task> OnUserInformationReceived { get; set; } = context => TaskCache.CompletedTask;
|
||||
|
||||
public virtual Task AuthenticationFailed(AuthenticationFailedContext context) => OnAuthenticationFailed(context);
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,10 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"Microsoft.AspNetCore.Authentication": "1.1.0-*",
|
||||
"Microsoft.Extensions.TaskCache.Sources": {
|
||||
"version": "1.1.0-*",
|
||||
"type": "build"
|
||||
},
|
||||
"Microsoft.IdentityModel.Protocols.OpenIdConnect": "2.0.0-*"
|
||||
},
|
||||
"frameworks": {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Internal;
|
||||
|
||||
namespace Microsoft.AspNetCore.Authentication.Twitter
|
||||
{
|
||||
|
|
@ -14,7 +15,7 @@ namespace Microsoft.AspNetCore.Authentication.Twitter
|
|||
/// <summary>
|
||||
/// Gets or sets the function that is invoked when the Authenticated method is invoked.
|
||||
/// </summary>
|
||||
public Func<TwitterCreatingTicketContext, Task> OnCreatingTicket { get; set; } = context => Task.FromResult(0);
|
||||
public Func<TwitterCreatingTicketContext, Task> OnCreatingTicket { get; set; } = context => TaskCache.CompletedTask;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the delegate that is invoked when the ApplyRedirect method is invoked.
|
||||
|
|
@ -22,7 +23,7 @@ namespace Microsoft.AspNetCore.Authentication.Twitter
|
|||
public Func<TwitterRedirectToAuthorizationEndpointContext, Task> OnRedirectToAuthorizationEndpoint { get; set; } = context =>
|
||||
{
|
||||
context.Response.Redirect(context.RedirectUri);
|
||||
return Task.FromResult(0);
|
||||
return TaskCache.CompletedTask;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -22,6 +22,10 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"Microsoft.AspNetCore.Authentication": "1.1.0-*",
|
||||
"Microsoft.Extensions.TaskCache.Sources": {
|
||||
"version": "1.1.0-*",
|
||||
"type": "build"
|
||||
},
|
||||
"Newtonsoft.Json": "9.0.1"
|
||||
},
|
||||
"frameworks": {
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ namespace Microsoft.AspNetCore.Authentication
|
|||
/// <returns></returns>
|
||||
protected virtual Task FinishResponseAsync()
|
||||
{
|
||||
return Task.FromResult(0);
|
||||
return TaskCache.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task HandleAutomaticChallengeIfNeeded()
|
||||
|
|
@ -283,7 +283,7 @@ namespace Microsoft.AspNetCore.Authentication
|
|||
|
||||
protected virtual Task HandleSignInAsync(SignInContext context)
|
||||
{
|
||||
return Task.FromResult(0);
|
||||
return TaskCache.CompletedTask;
|
||||
}
|
||||
|
||||
public async Task SignOutAsync(SignOutContext context)
|
||||
|
|
@ -308,7 +308,7 @@ namespace Microsoft.AspNetCore.Authentication
|
|||
|
||||
protected virtual Task HandleSignOutAsync(SignOutContext context)
|
||||
{
|
||||
return Task.FromResult(0);
|
||||
return TaskCache.CompletedTask;
|
||||
}
|
||||
|
||||
protected virtual Task<bool> HandleForbiddenAsync(ChallengeContext context)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.Features.Authentication;
|
||||
using Microsoft.Extensions.Internal;
|
||||
|
||||
namespace Microsoft.AspNetCore.Authentication
|
||||
{
|
||||
|
|
@ -48,7 +49,7 @@ namespace Microsoft.AspNetCore.Authentication
|
|||
{
|
||||
return PriorHandler.ChallengeAsync(context);
|
||||
}
|
||||
return Task.FromResult(0);
|
||||
return TaskCache.CompletedTask;
|
||||
}
|
||||
|
||||
public void GetDescriptions(DescribeSchemesContext context)
|
||||
|
|
@ -65,7 +66,7 @@ namespace Microsoft.AspNetCore.Authentication
|
|||
{
|
||||
return PriorHandler.SignInAsync(context);
|
||||
}
|
||||
return Task.FromResult(0);
|
||||
return TaskCache.CompletedTask;
|
||||
}
|
||||
|
||||
public Task SignOutAsync(SignOutContext context)
|
||||
|
|
@ -74,7 +75,7 @@ namespace Microsoft.AspNetCore.Authentication
|
|||
{
|
||||
return PriorHandler.SignOutAsync(context);
|
||||
}
|
||||
return Task.FromResult(0);
|
||||
return TaskCache.CompletedTask;
|
||||
}
|
||||
|
||||
public void RegisterAuthenticationHandler(IHttpAuthenticationFeature auth)
|
||||
|
|
|
|||
|
|
@ -3,14 +3,15 @@
|
|||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Internal;
|
||||
|
||||
namespace Microsoft.AspNetCore.Authentication
|
||||
{
|
||||
public class RemoteAuthenticationEvents : IRemoteAuthenticationEvents
|
||||
{
|
||||
public Func<FailureContext, Task> OnRemoteFailure { get; set; } = context => Task.FromResult(0);
|
||||
public Func<FailureContext, Task> OnRemoteFailure { get; set; } = context => TaskCache.CompletedTask;
|
||||
|
||||
public Func<TicketReceivedContext, Task> OnTicketReceived { get; set; } = context => Task.FromResult(0);
|
||||
public Func<TicketReceivedContext, Task> OnTicketReceived { get; set; } = context => TaskCache.CompletedTask;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when there is a remote failure
|
||||
|
|
|
|||
|
|
@ -29,6 +29,10 @@
|
|||
"type": "build",
|
||||
"version": "1.1.0-*"
|
||||
},
|
||||
"Microsoft.Extensions.TaskCache.Sources": {
|
||||
"version": "1.1.0-*",
|
||||
"type": "build"
|
||||
},
|
||||
"Microsoft.Extensions.Options": "1.1.0-*",
|
||||
"Microsoft.Extensions.WebEncoders": "1.1.0-*"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Internal;
|
||||
|
||||
namespace Microsoft.AspNetCore.Authorization.Infrastructure
|
||||
{
|
||||
|
|
@ -67,7 +68,7 @@ namespace Microsoft.AspNetCore.Authorization.Infrastructure
|
|||
context.Succeed(requirement);
|
||||
}
|
||||
}
|
||||
return Task.FromResult(0);
|
||||
return TaskCache.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Internal;
|
||||
|
||||
namespace Microsoft.AspNetCore.Authorization.Infrastructure
|
||||
{
|
||||
|
|
@ -27,7 +28,7 @@ namespace Microsoft.AspNetCore.Authorization.Infrastructure
|
|||
{
|
||||
context.Succeed(requirement);
|
||||
}
|
||||
return Task.FromResult(0);
|
||||
return TaskCache.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Internal;
|
||||
|
||||
namespace Microsoft.AspNetCore.Authorization.Infrastructure
|
||||
{
|
||||
|
|
@ -46,7 +47,7 @@ namespace Microsoft.AspNetCore.Authorization.Infrastructure
|
|||
context.Succeed(requirement);
|
||||
}
|
||||
}
|
||||
return Task.FromResult(0);
|
||||
return TaskCache.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Internal;
|
||||
|
||||
namespace Microsoft.AspNetCore.Authorization.Infrastructure
|
||||
{
|
||||
|
|
@ -61,7 +62,7 @@ namespace Microsoft.AspNetCore.Authorization.Infrastructure
|
|||
context.Succeed(requirement);
|
||||
}
|
||||
}
|
||||
return Task.FromResult(0);
|
||||
return TaskCache.CompletedTask;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,11 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"Microsoft.Extensions.Logging.Abstractions": "1.1.0-*",
|
||||
"Microsoft.Extensions.Options": "1.1.0-*"
|
||||
"Microsoft.Extensions.Options": "1.1.0-*",
|
||||
"Microsoft.Extensions.TaskCache.Sources": {
|
||||
"version": "1.1.0-*",
|
||||
"type": "build"
|
||||
}
|
||||
},
|
||||
"frameworks": {
|
||||
"net451": {
|
||||
|
|
|
|||
Loading…
Reference in New Issue