diff --git a/src/Microsoft.AspNet.Authentication.Cookies/Events/CookieAuthenticationEvents.cs b/src/Microsoft.AspNet.Authentication.Cookies/Events/CookieAuthenticationEvents.cs
index cbe3a71711..6c65bb857d 100644
--- a/src/Microsoft.AspNet.Authentication.Cookies/Events/CookieAuthenticationEvents.cs
+++ b/src/Microsoft.AspNet.Authentication.Cookies/Events/CookieAuthenticationEvents.cs
@@ -14,101 +14,70 @@ namespace Microsoft.AspNet.Authentication.Cookies
public class CookieAuthenticationEvents : ICookieAuthenticationEvents
{
///
- /// Create a new instance of the default events.
+ /// A delegate assigned to this property will be invoked when the related method is called
///
- public CookieAuthenticationEvents()
- {
- OnValidatePrincipal = context => Task.FromResult(0);
- OnResponseSignIn = context => { };
- OnResponseSignedIn = context => { };
- OnResponseSignOut = context => { };
- OnApplyRedirect = context => context.Response.Redirect(context.RedirectUri);
- OnException = context => { };
- }
+ public Func OnValidatePrincipal { get; set; } = context => Task.FromResult(0);
///
/// A delegate assigned to this property will be invoked when the related method is called
///
- public Func OnValidatePrincipal { get; set; }
+ public Action OnResponseSignIn { get; set; } = context => { };
///
/// A delegate assigned to this property will be invoked when the related method is called
///
- public Action OnResponseSignIn { get; set; }
+ public Action OnResponseSignedIn { get; set; } = context => { };
///
/// A delegate assigned to this property will be invoked when the related method is called
///
- public Action OnResponseSignedIn { get; set; }
+ public Action OnResponseSignOut { get; set; } = context => { };
///
/// A delegate assigned to this property will be invoked when the related method is called
///
- public Action OnResponseSignOut { get; set; }
+ public Action OnApplyRedirect { get; set; } = context => context.Response.Redirect(context.RedirectUri);
///
/// A delegate assigned to this property will be invoked when the related method is called
///
- public Action OnApplyRedirect { get; set; }
-
- ///
- /// A delegate assigned to this property will be invoked when the related method is called
- ///
- public Action OnException { get; set; }
+ public Action OnException { get; set; } = context => { };
///
/// Implements the interface method by invoking the related delegate method
///
///
///
- public virtual Task ValidatePrincipal(CookieValidatePrincipalContext context)
- {
- return OnValidatePrincipal.Invoke(context);
- }
+ public virtual Task ValidatePrincipal(CookieValidatePrincipalContext context) => OnValidatePrincipal(context);
///
/// Implements the interface method by invoking the related delegate method
///
///
- public virtual void ResponseSignIn(CookieResponseSignInContext context)
- {
- OnResponseSignIn.Invoke(context);
- }
+ public virtual void ResponseSignIn(CookieResponseSignInContext context) => OnResponseSignIn(context);
///
/// Implements the interface method by invoking the related delegate method
///
///
- public virtual void ResponseSignedIn(CookieResponseSignedInContext context)
- {
- OnResponseSignedIn.Invoke(context);
- }
+ public virtual void ResponseSignedIn(CookieResponseSignedInContext context) => OnResponseSignedIn(context);
///
/// Implements the interface method by invoking the related delegate method
///
///
- public virtual void ResponseSignOut(CookieResponseSignOutContext context)
- {
- OnResponseSignOut.Invoke(context);
- }
+ public virtual void ResponseSignOut(CookieResponseSignOutContext context) => OnResponseSignOut(context);
///
/// Implements the interface method by invoking the related delegate method
///
/// Contains information about the event
- public virtual void ApplyRedirect(CookieApplyRedirectContext context)
- {
- OnApplyRedirect.Invoke(context);
- }
+ public virtual void ApplyRedirect(CookieApplyRedirectContext context) => OnApplyRedirect(context);
///
/// Implements the interface method by invoking the related delegate method
///
/// Contains information about the event
- public virtual void Exception(CookieExceptionContext context)
- {
- OnException.Invoke(context);
- }
+ public virtual void Exception(CookieExceptionContext context) => OnException(context);
}
}
\ No newline at end of file
diff --git a/src/Microsoft.AspNet.Authentication.JwtBearer/Events/IJwtBearerAuthenticationEvents.cs b/src/Microsoft.AspNet.Authentication.JwtBearer/Events/IJwtBearerAuthenticationEvents.cs
new file mode 100644
index 0000000000..cd1a6fc087
--- /dev/null
+++ b/src/Microsoft.AspNet.Authentication.JwtBearer/Events/IJwtBearerAuthenticationEvents.cs
@@ -0,0 +1,43 @@
+// Copyright (c) .NET Foundation. All rights reserved.
+// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+
+using System;
+using System.Threading.Tasks;
+using Microsoft.AspNet.Http;
+
+///
+/// Specifies events which the invokes to enable developer control over the authentication process. />
+///
+namespace Microsoft.AspNet.Authentication.JwtBearer
+{
+ ///
+ /// Jwt bearer token middleware events.
+ ///
+ public interface IJwtBearerAuthenticationEvents
+ {
+ ///
+ /// Invoked if exceptions are thrown during request processing. The exceptions will be re-thrown after this event unless suppressed.
+ ///
+ Task AuthenticationFailed(AuthenticationFailedContext context);
+
+ ///
+ /// Invoked when a protocol message is first received.
+ ///
+ Task MessageReceived(MessageReceivedContext context);
+
+ ///
+ /// Invoked with the security token that has been extracted from the protocol message.
+ ///
+ Task SecurityTokenReceived(SecurityTokenReceivedContext context);
+
+ ///
+ /// Invoked after the security token has passed validation and a ClaimsIdentity has been generated.
+ ///
+ Task SecurityTokenValidated(SecurityTokenValidatedContext context);
+
+ ///
+ /// Invoked to apply a challenge sent back to the caller.
+ ///
+ Task ApplyChallenge(AuthenticationChallengeContext context);
+ }
+}
diff --git a/src/Microsoft.AspNet.Authentication.JwtBearer/Events/JwtBearerAuthenticationEvents.cs b/src/Microsoft.AspNet.Authentication.JwtBearer/Events/JwtBearerAuthenticationEvents.cs
index a8d674d1e9..4b06937a70 100644
--- a/src/Microsoft.AspNet.Authentication.JwtBearer/Events/JwtBearerAuthenticationEvents.cs
+++ b/src/Microsoft.AspNet.Authentication.JwtBearer/Events/JwtBearerAuthenticationEvents.cs
@@ -11,45 +11,47 @@ using Microsoft.AspNet.Http;
namespace Microsoft.AspNet.Authentication.JwtBearer
{
///
- /// Jwt bearer token middleware provider
+ /// Jwt bearer token middleware events.
///
- public class JwtBearerAuthenticationEvents
+ public class JwtBearerAuthenticationEvents : IJwtBearerAuthenticationEvents
{
- ///
- /// Initializes a new instance of the class
- ///
- public JwtBearerAuthenticationEvents()
- {
- ApplyChallenge = context => { context.HttpContext.Response.Headers.Append("WWW-Authenticate", context.Options.Challenge); return Task.FromResult(0); };
- AuthenticationFailed = context => Task.FromResult(0);
- MessageReceived = context => Task.FromResult(0);
- SecurityTokenReceived = context => Task.FromResult(0);
- SecurityTokenValidated = context => Task.FromResult(0);
- }
-
///
/// Invoked if exceptions are thrown during request processing. The exceptions will be re-thrown after this event unless suppressed.
///
- public Func AuthenticationFailed { get; set; }
+ public Func OnAuthenticationFailed { get; set; } = context => Task.FromResult(0);
///
/// Invoked when a protocol message is first received.
///
- public Func MessageReceived { get; set; }
+ public Func OnMessageReceived { get; set; } = context => Task.FromResult(0);
///
/// Invoked with the security token that has been extracted from the protocol message.
///
- public Func SecurityTokenReceived { get; set; }
+ public Func OnSecurityTokenReceived { get; set; } = context => Task.FromResult(0);
///
/// Invoked after the security token has passed validation and a ClaimsIdentity has been generated.
///
- public Func SecurityTokenValidated { get; set; }
+ public Func OnSecurityTokenValidated { get; set; } = context => Task.FromResult(0);
///
/// Invoked to apply a challenge sent back to the caller.
///
- public Func ApplyChallenge { get; set; }
+ public Func OnApplyChallenge { get; set; } = context =>
+ {
+ context.HttpContext.Response.Headers.Append("WWW-Authenticate", context.Options.Challenge);
+ return Task.FromResult(0);
+ };
+
+ public virtual Task AuthenticationFailed(AuthenticationFailedContext context) => OnAuthenticationFailed(context);
+
+ public virtual Task MessageReceived(MessageReceivedContext context) => OnMessageReceived(context);
+
+ public virtual Task SecurityTokenReceived(SecurityTokenReceivedContext context) => OnSecurityTokenReceived(context);
+
+ public virtual Task SecurityTokenValidated(SecurityTokenValidatedContext context) => OnSecurityTokenValidated(context);
+
+ public virtual Task ApplyChallenge(AuthenticationChallengeContext context) => OnApplyChallenge(context);
}
}
diff --git a/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerAuthenticationOptions.cs b/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerAuthenticationOptions.cs
index 07d0859f20..373095f822 100644
--- a/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerAuthenticationOptions.cs
+++ b/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerAuthenticationOptions.cs
@@ -52,7 +52,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
/// The application may implement the interface fully, or it may create an instance of JwtBearerAuthenticationEvents
/// and assign delegates only to the events it wants to process.
///
- public JwtBearerAuthenticationEvents Events { get; set; } = new JwtBearerAuthenticationEvents();
+ public IJwtBearerAuthenticationEvents Events { get; set; } = new JwtBearerAuthenticationEvents();
///
/// The HttpMessageHandler used to retrieve metadata.
diff --git a/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/IOpenIdConnectAuthenticationEvents.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/IOpenIdConnectAuthenticationEvents.cs
new file mode 100644
index 0000000000..4c69a1b39f
--- /dev/null
+++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/IOpenIdConnectAuthenticationEvents.cs
@@ -0,0 +1,48 @@
+// Copyright (c) .NET Foundation. All rights reserved.
+// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+
+using System.Threading.Tasks;
+
+namespace Microsoft.AspNet.Authentication.OpenIdConnect
+{
+ ///
+ /// Specifies events which the invokes to enable developer control over the authentication process.
+ ///
+ public interface IOpenIdConnectAuthenticationEvents
+ {
+ ///
+ /// Invoked if exceptions are thrown during request processing. The exceptions will be re-thrown after this event unless suppressed.
+ ///
+ Task AuthenticationFailed(AuthenticationFailedContext context);
+
+ ///
+ /// Invoked after security token validation if an authorization code is present in the protocol message.
+ ///
+ Task AuthorizationCodeReceived(AuthorizationCodeReceivedContext context);
+
+ ///
+ /// Invoked after "authorization code" is redeemed for tokens at the token endpoint.
+ ///
+ Task AuthorizationCodeRedeemed(AuthorizationCodeRedeemedContext context);
+
+ ///
+ /// Invoked when a protocol message is first received.
+ ///
+ Task MessageReceived(MessageReceivedContext context);
+
+ ///
+ /// Invoked to manipulate redirects to the identity provider for SignIn, SignOut, or Challenge.
+ ///
+ Task RedirectToIdentityProvider(RedirectToIdentityProviderContext context);
+
+ ///
+ /// Invoked with the security token that has been extracted from the protocol message.
+ ///
+ Task SecurityTokenReceived(SecurityTokenReceivedContext context);
+
+ ///
+ /// Invoked after the security token has passed validation and a ClaimsIdentity has been generated.
+ ///
+ Task SecurityTokenValidated(SecurityTokenValidatedContext context);
+ }
+}
\ No newline at end of file
diff --git a/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/OpenIdConnectAuthenticationEvents.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/OpenIdConnectAuthenticationEvents.cs
index 134ce48929..9f21f74537 100644
--- a/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/OpenIdConnectAuthenticationEvents.cs
+++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/OpenIdConnectAuthenticationEvents.cs
@@ -9,55 +9,55 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
///
/// Specifies events which the invokes to enable developer control over the authentication process.
///
- public class OpenIdConnectAuthenticationEvents
+ public class OpenIdConnectAuthenticationEvents : IOpenIdConnectAuthenticationEvents
{
- ///
- /// Creates a new set of events. Each event has a default no-op behavior unless otherwise documented.
- ///
- public OpenIdConnectAuthenticationEvents()
- {
- AuthenticationFailed = context => Task.FromResult(0);
- AuthorizationCodeReceived = context => Task.FromResult(0);
- AuthorizationCodeRedeemed = context => Task.FromResult(0);
- MessageReceived = context => Task.FromResult(0);
- RedirectToIdentityProvider = context => Task.FromResult(0);
- SecurityTokenReceived = context => Task.FromResult(0);
- SecurityTokenValidated = context => Task.FromResult(0);
- }
-
///
/// Invoked if exceptions are thrown during request processing. The exceptions will be re-thrown after this event unless suppressed.
///
- public Func AuthenticationFailed { get; set; }
+ public Func OnAuthenticationFailed { get; set; } = context => Task.FromResult(0);
///
/// Invoked after security token validation if an authorization code is present in the protocol message.
///
- public Func AuthorizationCodeReceived { get; set; }
+ public Func OnAuthorizationCodeReceived { get; set; } = context => Task.FromResult(0);
///
/// Invoked after "authorization code" is redeemed for tokens at the token endpoint.
///
- public Func AuthorizationCodeRedeemed { get; set; }
+ public Func OnAuthorizationCodeRedeemed { get; set; } = context => Task.FromResult(0);
///
/// Invoked when a protocol message is first received.
///
- public Func MessageReceived { get; set; }
+ public Func OnMessageReceived { get; set; } = context => Task.FromResult(0);
///
/// Invoked to manipulate redirects to the identity provider for SignIn, SignOut, or Challenge.
///
- public Func RedirectToIdentityProvider { get; set; }
+ public Func OnRedirectToIdentityProvider { get; set; } = context => Task.FromResult(0);
///
/// Invoked with the security token that has been extracted from the protocol message.
///
- public Func SecurityTokenReceived { get; set; }
+ public Func OnSecurityTokenReceived { get; set; } = context => Task.FromResult(0);
///
/// Invoked after the security token has passed validation and a ClaimsIdentity has been generated.
///
- public Func SecurityTokenValidated { get; set; }
+ public Func OnSecurityTokenValidated { get; set; } = context => Task.FromResult(0);
+
+ public virtual Task AuthenticationFailed(AuthenticationFailedContext context) => OnAuthenticationFailed(context);
+
+ public virtual Task AuthorizationCodeReceived(AuthorizationCodeReceivedContext context) => OnAuthorizationCodeReceived(context);
+
+ public virtual Task AuthorizationCodeRedeemed(AuthorizationCodeRedeemedContext context) => OnAuthorizationCodeRedeemed(context);
+
+ public virtual Task MessageReceived(MessageReceivedContext context) => OnMessageReceived(context);
+
+ public virtual Task RedirectToIdentityProvider(RedirectToIdentityProviderContext context) => OnRedirectToIdentityProvider(context);
+
+ public virtual Task SecurityTokenReceived(SecurityTokenReceivedContext context) => OnSecurityTokenReceived(context);
+
+ public virtual Task SecurityTokenValidated(SecurityTokenValidatedContext context) => OnSecurityTokenValidated(context);
}
}
\ No newline at end of file
diff --git a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationOptions.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationOptions.cs
index 045b279cfd..6809b571a7 100644
--- a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationOptions.cs
+++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationOptions.cs
@@ -160,9 +160,9 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
public bool CacheNonces { get; set; }
///
- /// Gets or sets the to notify when processing OpenIdConnect messages.
+ /// Gets or sets the to notify when processing OpenIdConnect messages.
///
- public OpenIdConnectAuthenticationEvents Events { get; set; } = new OpenIdConnectAuthenticationEvents();
+ public IOpenIdConnectAuthenticationEvents Events { get; set; } = new OpenIdConnectAuthenticationEvents();
///
/// Gets or sets the that is used to ensure that the 'id_token' received
diff --git a/src/Microsoft.AspNet.Authentication.Twitter/Events/TwitterAuthenticationEvents.cs b/src/Microsoft.AspNet.Authentication.Twitter/Events/TwitterAuthenticationEvents.cs
index 3fcd6fe84b..deae986da7 100644
--- a/src/Microsoft.AspNet.Authentication.Twitter/Events/TwitterAuthenticationEvents.cs
+++ b/src/Microsoft.AspNet.Authentication.Twitter/Events/TwitterAuthenticationEvents.cs
@@ -11,58 +11,39 @@ namespace Microsoft.AspNet.Authentication.Twitter
///
public class TwitterAuthenticationEvents : ITwitterAuthenticationEvents
{
- ///
- /// Initializes a
- ///
- public TwitterAuthenticationEvents()
- {
- OnAuthenticated = context => Task.FromResult