diff --git a/samples/SocialSample/Startup.cs b/samples/SocialSample/Startup.cs index 2721b5807e..47672d4b03 100644 --- a/samples/SocialSample/Startup.cs +++ b/samples/SocialSample/Startup.cs @@ -135,16 +135,16 @@ namespace CookieSample options.ClaimsIssuer = "OAuth2-Github"; options.SaveTokensAsClaims = false; // Retrieving user information is unique to each provider. - options.Notifications = new OAuthAuthenticationNotifications + options.Events = new OAuthAuthenticationEvents { - OnAuthenticated = async notification => + OnAuthenticated = async context => { // Get the GitHub user - var request = new HttpRequestMessage(HttpMethod.Get, notification.Options.UserInformationEndpoint); - request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", notification.AccessToken); + var request = new HttpRequestMessage(HttpMethod.Get, context.Options.UserInformationEndpoint); + request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", context.AccessToken); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); - var response = await notification.Backchannel.SendAsync(request, notification.HttpContext.RequestAborted); + var response = await context.Backchannel.SendAsync(request, context.HttpContext.RequestAborted); response.EnsureSuccessStatusCode(); var user = JObject.Parse(await response.Content.ReadAsStringAsync()); @@ -152,33 +152,33 @@ namespace CookieSample var identifier = user.Value("id"); if (!string.IsNullOrEmpty(identifier)) { - notification.Identity.AddClaim(new Claim( + context.Identity.AddClaim(new Claim( ClaimTypes.NameIdentifier, identifier, - ClaimValueTypes.String, notification.Options.ClaimsIssuer)); + ClaimValueTypes.String, context.Options.ClaimsIssuer)); } var userName = user.Value("login"); if (!string.IsNullOrEmpty(userName)) { - notification.Identity.AddClaim(new Claim( + context.Identity.AddClaim(new Claim( ClaimsIdentity.DefaultNameClaimType, userName, - ClaimValueTypes.String, notification.Options.ClaimsIssuer)); + ClaimValueTypes.String, context.Options.ClaimsIssuer)); } var name = user.Value("name"); if (!string.IsNullOrEmpty(name)) { - notification.Identity.AddClaim(new Claim( + context.Identity.AddClaim(new Claim( "urn:github:name", name, - ClaimValueTypes.String, notification.Options.ClaimsIssuer)); + ClaimValueTypes.String, context.Options.ClaimsIssuer)); } var link = user.Value("url"); if (!string.IsNullOrEmpty(link)) { - notification.Identity.AddClaim(new Claim( + context.Identity.AddClaim(new Claim( "urn:github:url", link, - ClaimValueTypes.String, notification.Options.ClaimsIssuer)); + ClaimValueTypes.String, context.Options.ClaimsIssuer)); } }, }; diff --git a/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationHandler.cs b/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationHandler.cs index d04af10481..95c4bec019 100644 --- a/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationHandler.cs @@ -114,7 +114,7 @@ namespace Microsoft.AspNet.Authentication.Cookies } var context = new CookieValidatePrincipalContext(Context, ticket, Options); - await Options.Notifications.ValidatePrincipal(context); + await Options.Events.ValidatePrincipal(context); if (context.Principal == null) { @@ -132,7 +132,7 @@ namespace Microsoft.AspNet.Authentication.Cookies { var exceptionContext = new CookieExceptionContext(Context, Options, CookieExceptionContext.ExceptionLocation.Authenticate, exception, ticket); - Options.Notifications.Exception(exceptionContext); + Options.Events.Exception(exceptionContext); if (exceptionContext.Rethrow) { throw; @@ -210,7 +210,7 @@ namespace Microsoft.AspNet.Authentication.Cookies { var exceptionContext = new CookieExceptionContext(Context, Options, CookieExceptionContext.ExceptionLocation.FinishResponse, exception, ticket); - Options.Notifications.Exception(exceptionContext); + Options.Events.Exception(exceptionContext); if (exceptionContext.Rethrow) { throw; @@ -249,7 +249,7 @@ namespace Microsoft.AspNet.Authentication.Cookies signInContext.Properties.ExpiresUtc = issuedUtc.Add(Options.ExpireTimeSpan); } - Options.Notifications.ResponseSignIn(signInContext); + Options.Events.ResponseSignIn(signInContext); if (signInContext.Properties.IsPersistent) { @@ -286,7 +286,7 @@ namespace Microsoft.AspNet.Authentication.Cookies signInContext.Principal, signInContext.Properties); - Options.Notifications.ResponseSignedIn(signedInContext); + Options.Events.ResponseSignedIn(signedInContext); var shouldLoginRedirect = Options.LoginPath.HasValue && OriginalPath == Options.LoginPath; ApplyHeaders(shouldLoginRedirect); @@ -295,7 +295,7 @@ namespace Microsoft.AspNet.Authentication.Cookies { var exceptionContext = new CookieExceptionContext(Context, Options, CookieExceptionContext.ExceptionLocation.SignIn, exception, ticket); - Options.Notifications.Exception(exceptionContext); + Options.Events.Exception(exceptionContext); if (exceptionContext.Rethrow) { throw; @@ -319,7 +319,7 @@ namespace Microsoft.AspNet.Authentication.Cookies Options, cookieOptions); - Options.Notifications.ResponseSignOut(context); + Options.Events.ResponseSignOut(context); Options.CookieManager.DeleteCookie( Context, @@ -333,7 +333,7 @@ namespace Microsoft.AspNet.Authentication.Cookies { var exceptionContext = new CookieExceptionContext(Context, Options, CookieExceptionContext.ExceptionLocation.SignOut, exception, ticket); - Options.Notifications.Exception(exceptionContext); + Options.Events.Exception(exceptionContext); if (exceptionContext.Rethrow) { throw; @@ -355,7 +355,7 @@ namespace Microsoft.AspNet.Authentication.Cookies && IsHostRelative(redirectUri)) { var redirectContext = new CookieApplyRedirectContext(Context, Options, redirectUri); - Options.Notifications.ApplyRedirect(redirectContext); + Options.Events.ApplyRedirect(redirectContext); } } } @@ -385,13 +385,13 @@ namespace Microsoft.AspNet.Authentication.Cookies Options.AccessDeniedPath; var redirectContext = new CookieApplyRedirectContext(Context, Options, accessDeniedUri); - Options.Notifications.ApplyRedirect(redirectContext); + Options.Events.ApplyRedirect(redirectContext); } catch (Exception exception) { var exceptionContext = new CookieExceptionContext(Context, Options, CookieExceptionContext.ExceptionLocation.Forbidden, exception, ticket: null); - Options.Notifications.Exception(exceptionContext); + Options.Events.Exception(exceptionContext); if (exceptionContext.Rethrow) { throw; @@ -412,13 +412,13 @@ namespace Microsoft.AspNet.Authentication.Cookies var loginUri = Options.LoginPath + QueryString.Create(Options.ReturnUrlParameter, redirectUri); var redirectContext = new CookieApplyRedirectContext(Context, Options, BuildRedirectUri(loginUri)); - Options.Notifications.ApplyRedirect(redirectContext); + Options.Events.ApplyRedirect(redirectContext); } catch (Exception exception) { var exceptionContext = new CookieExceptionContext(Context, Options, CookieExceptionContext.ExceptionLocation.Unauthorized, exception, ticket: null); - Options.Notifications.Exception(exceptionContext); + Options.Events.Exception(exceptionContext); if (exceptionContext.Rethrow) { throw; diff --git a/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationMiddleware.cs b/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationMiddleware.cs index 6765e4d815..d7de7fbecd 100644 --- a/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationMiddleware.cs @@ -22,9 +22,9 @@ namespace Microsoft.AspNet.Authentication.Cookies ConfigureOptions configureOptions) : base(next, options, loggerFactory, urlEncoder, configureOptions) { - if (Options.Notifications == null) + if (Options.Events == null) { - Options.Notifications = new CookieAuthenticationNotifications(); + Options.Events = new CookieAuthenticationEvents(); } if (String.IsNullOrEmpty(Options.CookieName)) { diff --git a/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationOptions.cs b/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationOptions.cs index 52a4d82efc..b8743d1843 100644 --- a/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationOptions.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationOptions.cs @@ -28,7 +28,7 @@ namespace Microsoft.AspNet.Authentication.Cookies CookieHttpOnly = true; CookieSecure = CookieSecureOption.SameAsRequest; SystemClock = new SystemClock(); - Notifications = new CookieAuthenticationNotifications(); + Events = new CookieAuthenticationEvents(); } /// @@ -116,10 +116,10 @@ namespace Microsoft.AspNet.Authentication.Cookies /// /// The Provider may be assigned to an instance of an object created by the application at startup time. The middleware - /// calls methods on the provider which give the application control at certain points where processing is occuring. + /// calls methods on the provider which give the application control at certain points where processing is occurring. /// If it is not provided a default instance is supplied which does nothing when the methods are called. /// - public ICookieAuthenticationNotifications Notifications { get; set; } + public ICookieAuthenticationEvents Events { get; set; } /// /// The TicketDataFormat is used to protect and unprotect the identity and other properties which are stored in the diff --git a/src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieApplyRedirectContext.cs b/src/Microsoft.AspNet.Authentication.Cookies/Events/CookieApplyRedirectContext.cs similarity index 100% rename from src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieApplyRedirectContext.cs rename to src/Microsoft.AspNet.Authentication.Cookies/Events/CookieApplyRedirectContext.cs diff --git a/src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieAuthenticationNotifications.cs b/src/Microsoft.AspNet.Authentication.Cookies/Events/CookieAuthenticationEvents.cs similarity index 94% rename from src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieAuthenticationNotifications.cs rename to src/Microsoft.AspNet.Authentication.Cookies/Events/CookieAuthenticationEvents.cs index 57218a9ad9..cbe3a71711 100644 --- a/src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieAuthenticationNotifications.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/Events/CookieAuthenticationEvents.cs @@ -7,16 +7,16 @@ using System.Threading.Tasks; namespace Microsoft.AspNet.Authentication.Cookies { /// - /// This default implementation of the ICookieAuthenticationNotifications may be used if the + /// This default implementation of the ICookieAuthenticationEvents may be used if the /// application only needs to override a few of the interface methods. This may be used as a base class /// or may be instantiated directly. /// - public class CookieAuthenticationNotifications : ICookieAuthenticationNotifications + public class CookieAuthenticationEvents : ICookieAuthenticationEvents { /// - /// Create a new instance of the default notifications. + /// Create a new instance of the default events. /// - public CookieAuthenticationNotifications() + public CookieAuthenticationEvents() { OnValidatePrincipal = context => Task.FromResult(0); OnResponseSignIn = context => { }; diff --git a/src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieExceptionContext.cs b/src/Microsoft.AspNet.Authentication.Cookies/Events/CookieExceptionContext.cs similarity index 100% rename from src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieExceptionContext.cs rename to src/Microsoft.AspNet.Authentication.Cookies/Events/CookieExceptionContext.cs diff --git a/src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieResponseSignInContext.cs b/src/Microsoft.AspNet.Authentication.Cookies/Events/CookieResponseSignInContext.cs similarity index 100% rename from src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieResponseSignInContext.cs rename to src/Microsoft.AspNet.Authentication.Cookies/Events/CookieResponseSignInContext.cs diff --git a/src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieResponseSignOutContext.cs b/src/Microsoft.AspNet.Authentication.Cookies/Events/CookieResponseSignOutContext.cs similarity index 100% rename from src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieResponseSignOutContext.cs rename to src/Microsoft.AspNet.Authentication.Cookies/Events/CookieResponseSignOutContext.cs diff --git a/src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieResponseSignedInContext.cs b/src/Microsoft.AspNet.Authentication.Cookies/Events/CookieResponseSignedInContext.cs similarity index 95% rename from src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieResponseSignedInContext.cs rename to src/Microsoft.AspNet.Authentication.Cookies/Events/CookieResponseSignedInContext.cs index 725a900544..a6a5c3469e 100644 --- a/src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieResponseSignedInContext.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/Events/CookieResponseSignedInContext.cs @@ -8,7 +8,7 @@ using Microsoft.AspNet.Http.Authentication; namespace Microsoft.AspNet.Authentication.Cookies { /// - /// Context object passed to the ICookieAuthenticationNotifications method ResponseSignedIn. + /// Context object passed to the ICookieAuthenticationEvents method ResponseSignedIn. /// public class CookieResponseSignedInContext : BaseContext { diff --git a/src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieValidateIdentityContext.cs b/src/Microsoft.AspNet.Authentication.Cookies/Events/CookieValidateIdentityContext.cs similarity index 100% rename from src/Microsoft.AspNet.Authentication.Cookies/Notifications/CookieValidateIdentityContext.cs rename to src/Microsoft.AspNet.Authentication.Cookies/Events/CookieValidateIdentityContext.cs diff --git a/src/Microsoft.AspNet.Authentication.Cookies/Notifications/ICookieAuthenticationNotifications.cs b/src/Microsoft.AspNet.Authentication.Cookies/Events/ICookieAuthenticationEvents.cs similarity index 98% rename from src/Microsoft.AspNet.Authentication.Cookies/Notifications/ICookieAuthenticationNotifications.cs rename to src/Microsoft.AspNet.Authentication.Cookies/Events/ICookieAuthenticationEvents.cs index 365396a924..b4caf0b556 100644 --- a/src/Microsoft.AspNet.Authentication.Cookies/Notifications/ICookieAuthenticationNotifications.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/Events/ICookieAuthenticationEvents.cs @@ -8,7 +8,7 @@ namespace Microsoft.AspNet.Authentication.Cookies /// /// Specifies callback methods which the invokes to enable developer control over the authentication process. /> /// - public interface ICookieAuthenticationNotifications + public interface ICookieAuthenticationEvents { /// /// Called each time a request principal has been validated by the middleware. By implementing this method the diff --git a/src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationHandler.cs b/src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationHandler.cs index 52e7b10371..8f3d343b46 100644 --- a/src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationHandler.cs @@ -62,7 +62,7 @@ namespace Microsoft.AspNet.Authentication.Facebook var payload = JObject.Parse(await response.Content.ReadAsStringAsync()); - var notification = new OAuthAuthenticatedContext(Context, Options, Backchannel, tokens, payload) + var context = new OAuthAuthenticatedContext(Context, Options, Backchannel, tokens, payload) { Properties = properties, Principal = new ClaimsPrincipal(identity) @@ -104,9 +104,9 @@ namespace Microsoft.AspNet.Authentication.Facebook identity.AddClaim(new Claim("urn:facebook:link", link, ClaimValueTypes.String, Options.ClaimsIssuer)); } - await Options.Notifications.Authenticated(notification); + await Options.Events.Authenticated(context); - return new AuthenticationTicket(notification.Principal, notification.Properties, notification.Options.AuthenticationScheme); + return new AuthenticationTicket(context.Principal, context.Properties, context.Options.AuthenticationScheme); } private string GenerateAppSecretProof(string accessToken) diff --git a/src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationHandler.cs b/src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationHandler.cs index 986338fd1c..7d55c5e676 100644 --- a/src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationHandler.cs @@ -32,7 +32,7 @@ namespace Microsoft.AspNet.Authentication.Google var payload = JObject.Parse(await response.Content.ReadAsStringAsync()); - var notification = new OAuthAuthenticatedContext(Context, Options, Backchannel, tokens, payload) + var context = new OAuthAuthenticatedContext(Context, Options, Backchannel, tokens, payload) { Properties = properties, Principal = new ClaimsPrincipal(identity) @@ -74,9 +74,9 @@ namespace Microsoft.AspNet.Authentication.Google identity.AddClaim(new Claim("urn:google:profile", profile, ClaimValueTypes.String, Options.ClaimsIssuer)); } - await Options.Notifications.Authenticated(notification); + await Options.Events.Authenticated(context); - return new AuthenticationTicket(notification.Principal, notification.Properties, notification.Options.AuthenticationScheme); + return new AuthenticationTicket(context.Principal, context.Properties, context.Options.AuthenticationScheme); } // TODO: Abstract this properties override pattern into the base class? diff --git a/src/Microsoft.AspNet.Authentication.JwtBearer/Notifications/AuthenticationChallengeNotification.cs b/src/Microsoft.AspNet.Authentication.JwtBearer/Events/AuthenticationChallengeContext.cs similarity index 58% rename from src/Microsoft.AspNet.Authentication.JwtBearer/Notifications/AuthenticationChallengeNotification.cs rename to src/Microsoft.AspNet.Authentication.JwtBearer/Events/AuthenticationChallengeContext.cs index 4be4376c20..58829ba879 100644 --- a/src/Microsoft.AspNet.Authentication.JwtBearer/Notifications/AuthenticationChallengeNotification.cs +++ b/src/Microsoft.AspNet.Authentication.JwtBearer/Events/AuthenticationChallengeContext.cs @@ -5,9 +5,9 @@ using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Authentication.JwtBearer { - public class AuthenticationChallengeNotification : BaseNotification + public class AuthenticationChallengeContext : BaseControlContext { - public AuthenticationChallengeNotification(HttpContext context, TOptions options) : base(context, options) + public AuthenticationChallengeContext(HttpContext context, TOptions options) : base(context, options) { } } diff --git a/src/Microsoft.AspNet.Authentication.JwtBearer/Notifications/JwtBearerAuthenticationNotifications.cs b/src/Microsoft.AspNet.Authentication.JwtBearer/Events/JwtBearerAuthenticationEvents.cs similarity index 53% rename from src/Microsoft.AspNet.Authentication.JwtBearer/Notifications/JwtBearerAuthenticationNotifications.cs rename to src/Microsoft.AspNet.Authentication.JwtBearer/Events/JwtBearerAuthenticationEvents.cs index 06984332ad..e2d1f500f3 100644 --- a/src/Microsoft.AspNet.Authentication.JwtBearer/Notifications/JwtBearerAuthenticationNotifications.cs +++ b/src/Microsoft.AspNet.Authentication.JwtBearer/Events/JwtBearerAuthenticationEvents.cs @@ -13,43 +13,43 @@ namespace Microsoft.AspNet.Authentication.JwtBearer /// /// Jwt bearer token middleware provider /// - public class JwtBearerAuthenticationNotifications + public class JwtBearerAuthenticationEvents { /// /// Initializes a new instance of the class /// - public JwtBearerAuthenticationNotifications() + public JwtBearerAuthenticationEvents() { - ApplyChallenge = notification => { notification.HttpContext.Response.Headers.Append("WWW-Authenticate", notification.Options.Challenge); return Task.FromResult(0); }; - AuthenticationFailed = notification => Task.FromResult(0); - MessageReceived = notification => Task.FromResult(0); - SecurityTokenReceived = notification => Task.FromResult(0); - SecurityTokenValidated = notification => Task.FromResult(0); + 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, Task> AuthenticationFailed { get; set; } + public Func, Task> AuthenticationFailed { get; set; } /// /// Invoked when a protocol message is first received. /// - public Func, Task> MessageReceived { get; set; } + public Func, Task> MessageReceived { get; set; } /// /// Invoked with the security token that has been extracted from the protocol message. /// - public Func, Task> SecurityTokenReceived { get; set; } + public Func, Task> SecurityTokenReceived { get; set; } /// /// Invoked after the security token has passed validation and a ClaimsIdentity has been generated. /// - public Func, Task> SecurityTokenValidated { get; set; } + public Func, Task> SecurityTokenValidated { get; set; } /// /// Invoked to apply a challenge sent back to the caller. /// - public Func, Task> ApplyChallenge { get; set; } + public Func, Task> ApplyChallenge { get; set; } } } diff --git a/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerAuthenticationHandler.cs b/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerAuthenticationHandler.cs index 6b740c5d0b..74edec3f67 100644 --- a/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerAuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerAuthenticationHandler.cs @@ -27,26 +27,26 @@ namespace Microsoft.AspNet.Authentication.JwtBearer try { // Give application opportunity to find from a different location, adjust, or reject token - var messageReceivedNotification = - new MessageReceivedNotification(Context, Options) + var messageReceivedContext = + new MessageReceivedContext(Context, Options) { ProtocolMessage = Context, }; - // notification can set the token - await Options.Notifications.MessageReceived(messageReceivedNotification); - if (messageReceivedNotification.HandledResponse) + // event can set the token + await Options.Events.MessageReceived(messageReceivedContext); + if (messageReceivedContext.HandledResponse) { - return messageReceivedNotification.AuthenticationTicket; + return messageReceivedContext.AuthenticationTicket; } - if (messageReceivedNotification.Skipped) + if (messageReceivedContext.Skipped) { return null; } // If application retrieved token from somewhere else, use that. - token = messageReceivedNotification.Token; + token = messageReceivedContext.Token; if (string.IsNullOrEmpty(token)) { @@ -71,20 +71,20 @@ namespace Microsoft.AspNet.Authentication.JwtBearer } // notify user token was received - var securityTokenReceivedNotification = - new SecurityTokenReceivedNotification(Context, Options) + var securityTokenReceivedContext = + new SecurityTokenReceivedContext(Context, Options) { ProtocolMessage = Context, SecurityToken = token, }; - await Options.Notifications.SecurityTokenReceived(securityTokenReceivedNotification); - if (securityTokenReceivedNotification.HandledResponse) + await Options.Events.SecurityTokenReceived(securityTokenReceivedContext); + if (securityTokenReceivedContext.HandledResponse) { - return securityTokenReceivedNotification.AuthenticationTicket; + return securityTokenReceivedContext.AuthenticationTicket; } - if (securityTokenReceivedNotification.Skipped) + if (securityTokenReceivedContext.Skipped) { return null; } @@ -117,19 +117,19 @@ namespace Microsoft.AspNet.Authentication.JwtBearer { var principal = validator.ValidateToken(token, validationParameters, out validatedToken); var ticket = new AuthenticationTicket(principal, new AuthenticationProperties(), Options.AuthenticationScheme); - var securityTokenValidatedNotification = new SecurityTokenValidatedNotification(Context, Options) + var securityTokenValidatedContext = new SecurityTokenValidatedContext(Context, Options) { ProtocolMessage = Context, AuthenticationTicket = ticket }; - await Options.Notifications.SecurityTokenValidated(securityTokenValidatedNotification); - if (securityTokenValidatedNotification.HandledResponse) + await Options.Events.SecurityTokenValidated(securityTokenValidatedContext); + if (securityTokenValidatedContext.HandledResponse) { - return securityTokenValidatedNotification.AuthenticationTicket; + return securityTokenValidatedContext.AuthenticationTicket; } - if (securityTokenValidatedNotification.Skipped) + if (securityTokenValidatedContext.Skipped) { return null; } @@ -144,26 +144,26 @@ namespace Microsoft.AspNet.Authentication.JwtBearer { Logger.LogError("Exception occurred while processing message", ex); - // Refresh the configuration for exceptions that may be caused by key rollovers. The user can also request a refresh in the notification. + // Refresh the configuration for exceptions that may be caused by key rollovers. The user can also request a refresh in the event. if (Options.RefreshOnIssuerKeyNotFound && ex.GetType().Equals(typeof(SecurityTokenSignatureKeyNotFoundException))) { Options.ConfigurationManager.RequestRefresh(); } - var authenticationFailedNotification = - new AuthenticationFailedNotification(Context, Options) + var authenticationFailedContext = + new AuthenticationFailedContext(Context, Options) { ProtocolMessage = Context, Exception = ex }; - await Options.Notifications.AuthenticationFailed(authenticationFailedNotification); - if (authenticationFailedNotification.HandledResponse) + await Options.Events.AuthenticationFailed(authenticationFailedContext); + if (authenticationFailedContext.HandledResponse) { - return authenticationFailedNotification.AuthenticationTicket; + return authenticationFailedContext.AuthenticationTicket; } - if (authenticationFailedNotification.Skipped) + if (authenticationFailedContext.Skipped) { return null; } @@ -175,7 +175,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer protected override async Task HandleUnauthorizedAsync(ChallengeContext context) { Response.StatusCode = 401; - await Options.Notifications.ApplyChallenge(new AuthenticationChallengeNotification(Context, Options)); + await Options.Events.ApplyChallenge(new AuthenticationChallengeContext(Context, Options)); return false; } diff --git a/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerAuthenticationMiddleware.cs b/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerAuthenticationMiddleware.cs index 0365b5e7b4..1cd69a7656 100644 --- a/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerAuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerAuthenticationMiddleware.cs @@ -34,9 +34,9 @@ namespace Microsoft.AspNet.Authentication.JwtBearer ConfigureOptions configureOptions) : base(next, options, loggerFactory, encoder, configureOptions) { - if (Options.Notifications == null) + if (Options.Events == null) { - Options.Notifications = new JwtBearerAuthenticationNotifications(); + Options.Events = new JwtBearerAuthenticationEvents(); } if (string.IsNullOrEmpty(Options.TokenValidationParameters.ValidAudience) && !string.IsNullOrEmpty(Options.Audience)) diff --git a/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerAuthenticationOptions.cs b/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerAuthenticationOptions.cs index 8e9c51e8b3..07d0859f20 100644 --- a/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerAuthenticationOptions.cs +++ b/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerAuthenticationOptions.cs @@ -49,10 +49,10 @@ namespace Microsoft.AspNet.Authentication.JwtBearer /// /// The object provided by the application to process events raised by the bearer authentication middleware. - /// The application may implement the interface fully, or it may create an instance of JwtBearerAuthenticationProvider + /// 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 JwtBearerAuthenticationNotifications Notifications { get; set; } = new JwtBearerAuthenticationNotifications(); + public JwtBearerAuthenticationEvents Events { get; set; } = new JwtBearerAuthenticationEvents(); /// /// The HttpMessageHandler used to retrieve metadata. diff --git a/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationHandler.cs b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationHandler.cs index 1c03b51183..4cec337008 100644 --- a/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationHandler.cs @@ -28,7 +28,7 @@ namespace Microsoft.AspNet.Authentication.MicrosoftAccount var payload = JObject.Parse(await response.Content.ReadAsStringAsync()); - var notification = new OAuthAuthenticatedContext(Context, Options, Backchannel, tokens, payload) + var context = new OAuthAuthenticatedContext(Context, Options, Backchannel, tokens, payload) { Properties = properties, Principal = new ClaimsPrincipal(identity) @@ -54,9 +54,9 @@ namespace Microsoft.AspNet.Authentication.MicrosoftAccount identity.AddClaim(new Claim(ClaimTypes.Email, email, ClaimValueTypes.String, Options.ClaimsIssuer)); } - await Options.Notifications.Authenticated(notification); + await Options.Events.Authenticated(context); - return new AuthenticationTicket(notification.Principal, notification.Properties, notification.Options.AuthenticationScheme); + return new AuthenticationTicket(context.Principal, context.Properties, context.Options.AuthenticationScheme); } } } diff --git a/src/Microsoft.AspNet.Authentication.OAuth/Notifications/BaseValidatingContext.cs b/src/Microsoft.AspNet.Authentication.OAuth/Events/BaseValidatingContext.cs similarity index 100% rename from src/Microsoft.AspNet.Authentication.OAuth/Notifications/BaseValidatingContext.cs rename to src/Microsoft.AspNet.Authentication.OAuth/Events/BaseValidatingContext.cs diff --git a/src/Microsoft.AspNet.Authentication.OAuth/Notifications/BaseValidatingTicketContext.cs b/src/Microsoft.AspNet.Authentication.OAuth/Events/BaseValidatingTicketContext.cs similarity index 100% rename from src/Microsoft.AspNet.Authentication.OAuth/Notifications/BaseValidatingTicketContext.cs rename to src/Microsoft.AspNet.Authentication.OAuth/Events/BaseValidatingTicketContext.cs diff --git a/src/Microsoft.AspNet.Authentication.OAuth/Notifications/IOAuthAuthenticationNotifications.cs b/src/Microsoft.AspNet.Authentication.OAuth/Events/IOAuthAuthenticationEvents.cs similarity index 89% rename from src/Microsoft.AspNet.Authentication.OAuth/Notifications/IOAuthAuthenticationNotifications.cs rename to src/Microsoft.AspNet.Authentication.OAuth/Events/IOAuthAuthenticationEvents.cs index 522f1cb162..5f402aa072 100644 --- a/src/Microsoft.AspNet.Authentication.OAuth/Notifications/IOAuthAuthenticationNotifications.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/Events/IOAuthAuthenticationEvents.cs @@ -10,11 +10,11 @@ namespace Microsoft.AspNet.Authentication.OAuth /// /// Specifies callback methods which the invokes to enable developer control over the authentication process. /// - public interface IOAuthAuthenticationNotifications + public interface IOAuthAuthenticationEvents { /// /// Invoked after the provider successfully authenticates a user. This can be used to retrieve user information. - /// This notification may not be invoked by sub-classes of OAuthAuthenticationHandler if they override CreateTicketAsync. + /// This event may not be invoked by sub-classes of OAuthAuthenticationHandler if they override CreateTicketAsync. /// /// Contains information about the login session. /// A representing the completed operation. diff --git a/src/Microsoft.AspNet.Authentication.OAuth/Notifications/OAuthApplyRedirectContext.cs b/src/Microsoft.AspNet.Authentication.OAuth/Events/OAuthApplyRedirectContext.cs similarity index 100% rename from src/Microsoft.AspNet.Authentication.OAuth/Notifications/OAuthApplyRedirectContext.cs rename to src/Microsoft.AspNet.Authentication.OAuth/Events/OAuthApplyRedirectContext.cs diff --git a/src/Microsoft.AspNet.Authentication.OAuth/Notifications/OAuthAuthenticatedContext.cs b/src/Microsoft.AspNet.Authentication.OAuth/Events/OAuthAuthenticatedContext.cs similarity index 100% rename from src/Microsoft.AspNet.Authentication.OAuth/Notifications/OAuthAuthenticatedContext.cs rename to src/Microsoft.AspNet.Authentication.OAuth/Events/OAuthAuthenticatedContext.cs diff --git a/src/Microsoft.AspNet.Authentication.OAuth/Notifications/OAuthAuthenticationNotifications.cs b/src/Microsoft.AspNet.Authentication.OAuth/Events/OAuthAuthenticationEvents.cs similarity index 91% rename from src/Microsoft.AspNet.Authentication.OAuth/Notifications/OAuthAuthenticationNotifications.cs rename to src/Microsoft.AspNet.Authentication.OAuth/Events/OAuthAuthenticationEvents.cs index 9716b14015..e2002bc8b4 100644 --- a/src/Microsoft.AspNet.Authentication.OAuth/Notifications/OAuthAuthenticationNotifications.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/Events/OAuthAuthenticationEvents.cs @@ -2,16 +2,14 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Security.Claims; using System.Threading.Tasks; -using Microsoft.AspNet.Http.Authentication; namespace Microsoft.AspNet.Authentication.OAuth { /// - /// Default implementation. + /// Default implementation. /// - public class OAuthAuthenticationNotifications : IOAuthAuthenticationNotifications + public class OAuthAuthenticationEvents : IOAuthAuthenticationEvents { /// /// Gets or sets the function that is invoked when the Authenticated method is invoked. diff --git a/src/Microsoft.AspNet.Authentication.OAuth/Notifications/OAuthChallengeContext.cs b/src/Microsoft.AspNet.Authentication.OAuth/Events/OAuthChallengeContext.cs similarity index 100% rename from src/Microsoft.AspNet.Authentication.OAuth/Notifications/OAuthChallengeContext.cs rename to src/Microsoft.AspNet.Authentication.OAuth/Events/OAuthChallengeContext.cs diff --git a/src/Microsoft.AspNet.Authentication.OAuth/Notifications/OAuthRequestTokenContext.cs b/src/Microsoft.AspNet.Authentication.OAuth/Events/OAuthRequestTokenContext.cs similarity index 100% rename from src/Microsoft.AspNet.Authentication.OAuth/Notifications/OAuthRequestTokenContext.cs rename to src/Microsoft.AspNet.Authentication.OAuth/Events/OAuthRequestTokenContext.cs diff --git a/src/Microsoft.AspNet.Authentication.OAuth/Notifications/OAuthReturnEndpointContext.cs b/src/Microsoft.AspNet.Authentication.OAuth/Events/OAuthReturnEndpointContext.cs similarity index 100% rename from src/Microsoft.AspNet.Authentication.OAuth/Notifications/OAuthReturnEndpointContext.cs rename to src/Microsoft.AspNet.Authentication.OAuth/Events/OAuthReturnEndpointContext.cs diff --git a/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationHandler.cs b/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationHandler.cs index 94f58ac466..a913531e28 100644 --- a/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationHandler.cs @@ -57,7 +57,7 @@ namespace Microsoft.AspNet.Authentication.OAuth }; ticket.Properties.RedirectUri = null; - await Options.Notifications.ReturnEndpoint(context); + await Options.Events.ReturnEndpoint(context); if (context.SignInScheme != null && context.Principal != null) { @@ -183,20 +183,20 @@ namespace Microsoft.AspNet.Authentication.OAuth protected virtual async Task CreateTicketAsync(ClaimsIdentity identity, AuthenticationProperties properties, OAuthTokenResponse tokens) { - var notification = new OAuthAuthenticatedContext(Context, Options, Backchannel, tokens) + var context = new OAuthAuthenticatedContext(Context, Options, Backchannel, tokens) { Principal = new ClaimsPrincipal(identity), Properties = properties }; - await Options.Notifications.Authenticated(notification); + await Options.Events.Authenticated(context); - if (notification.Principal?.Identity == null) + if (context.Principal?.Identity == null) { return null; } - return new AuthenticationTicket(notification.Principal, notification.Properties, Options.AuthenticationScheme); + return new AuthenticationTicket(context.Principal, context.Properties, Options.AuthenticationScheme); } protected override Task HandleUnauthorizedAsync([NotNull] ChallengeContext context) @@ -215,7 +215,7 @@ namespace Microsoft.AspNet.Authentication.OAuth var redirectContext = new OAuthApplyRedirectContext( Context, Options, properties, authorizationEndpoint); - Options.Notifications.ApplyRedirect(redirectContext); + Options.Events.ApplyRedirect(redirectContext); return Task.FromResult(true); } diff --git a/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationMiddleware.cs b/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationMiddleware.cs index a9f326f8c3..1b71de47b4 100644 --- a/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationMiddleware.cs @@ -63,9 +63,9 @@ namespace Microsoft.AspNet.Authentication.OAuth throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Exception_OptionMustBeProvided, nameof(Options.TokenEndpoint))); } - if (Options.Notifications == null) + if (Options.Events == null) { - Options.Notifications = new OAuthAuthenticationNotifications(); + Options.Events = new OAuthAuthenticationEvents(); } if (Options.StateDataFormat == null) diff --git a/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationOptions.cs b/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationOptions.cs index 96cf1e9cfc..19d7e4abfb 100644 --- a/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationOptions.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationOptions.cs @@ -38,7 +38,7 @@ namespace Microsoft.AspNet.Authentication.OAuth /// /// Gets or sets the URI the middleware will access to obtain the user information. /// This value is not used in the default implementation, it is for use in custom implementations of - /// IOAuthAuthenticationNotifications.Authenticated or OAuthAuthenticationHandler.CreateTicketAsync. + /// IOAuthAuthenticationEvents.Authenticated or OAuthAuthenticationHandler.CreateTicketAsync. /// public string UserInformationEndpoint { get; set; } @@ -80,9 +80,9 @@ namespace Microsoft.AspNet.Authentication.OAuth public HttpMessageHandler BackchannelHttpHandler { get; set; } /// - /// Gets or sets the used to handle authentication events. + /// Gets or sets the used to handle authentication events. /// - public IOAuthAuthenticationNotifications Notifications { get; set; } = new OAuthAuthenticationNotifications(); + public IOAuthAuthenticationEvents Events { get; set; } = new OAuthAuthenticationEvents(); /// /// A list of permissions to request. diff --git a/src/Microsoft.AspNet.Authentication.OpenIdConnect/Notifications/AuthorizationCodeReceivedNotification.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/AuthorizationCodeReceivedContext.cs similarity index 75% rename from src/Microsoft.AspNet.Authentication.OpenIdConnect/Notifications/AuthorizationCodeReceivedNotification.cs rename to src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/AuthorizationCodeReceivedContext.cs index 830c336121..5fdd57e6b8 100644 --- a/src/Microsoft.AspNet.Authentication.OpenIdConnect/Notifications/AuthorizationCodeReceivedNotification.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/AuthorizationCodeReceivedContext.cs @@ -9,14 +9,14 @@ using System.IdentityModel.Tokens.Jwt; namespace Microsoft.AspNet.Authentication.OpenIdConnect { /// - /// This Notification can be used to be informed when an 'AuthorizationCode' is received over the OpenIdConnect protocol. + /// This Context can be used to be informed when an 'AuthorizationCode' is received over the OpenIdConnect protocol. /// - public class AuthorizationCodeReceivedNotification : BaseNotification + public class AuthorizationCodeReceivedContext : BaseControlContext { /// - /// Creates a + /// Creates a /// - public AuthorizationCodeReceivedNotification(HttpContext context, OpenIdConnectAuthenticationOptions options) : base(context, options) + public AuthorizationCodeReceivedContext(HttpContext context, OpenIdConnectAuthenticationOptions options) : base(context, options) { } diff --git a/src/Microsoft.AspNet.Authentication.OpenIdConnect/Notifications/AuthorizationCodeRedeemedNotification.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/AuthorizationCodeRedeemedContext.cs similarity index 65% rename from src/Microsoft.AspNet.Authentication.OpenIdConnect/Notifications/AuthorizationCodeRedeemedNotification.cs rename to src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/AuthorizationCodeRedeemedContext.cs index c9b328e8c5..0b54f6ae8e 100644 --- a/src/Microsoft.AspNet.Authentication.OpenIdConnect/Notifications/AuthorizationCodeRedeemedNotification.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/AuthorizationCodeRedeemedContext.cs @@ -4,14 +4,14 @@ using Microsoft.IdentityModel.Protocols.OpenIdConnect; namespace Microsoft.AspNet.Authentication.OpenIdConnect { /// - /// This Notification can be used to be informed when an 'AuthorizationCode' is redeemed for tokens at the token endpoint. + /// This Context can be used to be informed when an 'AuthorizationCode' is redeemed for tokens at the token endpoint. /// - public class AuthorizationCodeRedeemedNotification : BaseNotification + public class AuthorizationCodeRedeemedContext : BaseControlContext { /// - /// Creates a + /// Creates a /// - public AuthorizationCodeRedeemedNotification(HttpContext context, OpenIdConnectAuthenticationOptions options) : base(context, options) + public AuthorizationCodeRedeemedContext(HttpContext context, OpenIdConnectAuthenticationOptions options) : base(context, options) { } diff --git a/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/OpenIdConnectAuthenticationEvents.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/OpenIdConnectAuthenticationEvents.cs new file mode 100644 index 0000000000..a084eb84c7 --- /dev/null +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/OpenIdConnectAuthenticationEvents.cs @@ -0,0 +1,64 @@ +// 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.IdentityModel.Protocols.OpenIdConnect; + +namespace Microsoft.AspNet.Authentication.OpenIdConnect +{ + /// + /// Specifies events which the invokes to enable developer control over the authentication process. + /// + public class OpenIdConnectAuthenticationEvents + { + /// + /// 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); + SecurityTokenReceived = context => Task.FromResult(0); + SecurityTokenValidated = context => Task.FromResult(0); + RedirectToIdentityProvider = 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, Task> AuthenticationFailed { get; set; } + + /// + /// Invoked after security token validation if an authorization code is present in the protocol message. + /// + public Func AuthorizationCodeReceived { get; set; } + + /// + /// Invoked after "authorization code" is redeemed for tokens at the token endpoint. + /// + public Func AuthorizationCodeRedeemed { get; set; } + + /// + /// Invoked when a protocol message is first received. + /// + public Func, Task> MessageReceived { get; set; } + + /// + /// Invoked to manipulate redirects to the identity provider for SignIn, SignOut, or Challenge. + /// + public Func, Task> RedirectToIdentityProvider { get; set; } + + /// + /// Invoked with the security token that has been extracted from the protocol message. + /// + public Func, Task> SecurityTokenReceived { get; set; } + + /// + /// Invoked after the security token has passed validation and a ClaimsIdentity has been generated. + /// + public Func, Task> SecurityTokenValidated { get; set; } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Authentication.OpenIdConnect/Notifications/OpenIdConnectAuthenticationNotifications.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/Notifications/OpenIdConnectAuthenticationNotifications.cs deleted file mode 100644 index b60e8cbcc3..0000000000 --- a/src/Microsoft.AspNet.Authentication.OpenIdConnect/Notifications/OpenIdConnectAuthenticationNotifications.cs +++ /dev/null @@ -1,65 +0,0 @@ -// 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.IdentityModel.Protocols.OpenIdConnect; - -namespace Microsoft.AspNet.Authentication.OpenIdConnect -{ - /// - /// Specifies events which the invokes to enable developer control over the authentication process. - /// - public class OpenIdConnectAuthenticationNotifications - { - /// - /// Creates a new set of notifications. Each notification has a default no-op behavior unless otherwise documented. - /// - public OpenIdConnectAuthenticationNotifications() - { - AuthenticationFailed = notification => Task.FromResult(0); - AuthorizationCodeReceived = notification => Task.FromResult(0); - AuthorizationCodeRedeemed = notificaion => Task.FromResult(0); - MessageReceived = notification => Task.FromResult(0); - SecurityTokenReceived = notification => Task.FromResult(0); - SecurityTokenValidated = notification => Task.FromResult(0); - RedirectToIdentityProvider = notification => Task.FromResult(0); - } - - /// - /// Invoked if exceptions are thrown during request processing. The exceptions will be re-thrown after this event unless suppressed. - /// - public Func, Task> AuthenticationFailed { get; set; } - - /// - /// Invoked after security token validation if an authorization code is present in the protocol message. - /// - public Func AuthorizationCodeReceived { get; set; } - - /// - /// Invoked after "authorization code" is redeemed for tokens at the token endpoint. - /// - public Func AuthorizationCodeRedeemed { get; set; } - - /// - /// Invoked when a protocol message is first received. - /// - public Func, Task> MessageReceived { get; set; } - - /// - /// Invoked to manipulate redirects to the identity provider for SignIn, SignOut, or Challenge. - /// - public Func, Task> RedirectToIdentityProvider { get; set; } - - /// - /// Invoked with the security token that has been extracted from the protocol message. - /// - public Func, Task> SecurityTokenReceived { get; set; } - - /// - /// Invoked after the security token has passed validation and a ClaimsIdentity has been generated. - /// - public Func, Task> SecurityTokenValidated { get; set; } - - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationHandler.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationHandler.cs index 9f3bc48317..8452f2fd26 100644 --- a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationHandler.cs @@ -89,24 +89,24 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect message.PostLogoutRedirectUri = Options.PostLogoutRedirectUri; } - var redirectToIdentityProviderNotification = new RedirectToIdentityProviderNotification(Context, Options) + var redirectToIdentityProviderContext = new RedirectToIdentityProviderContext(Context, Options) { ProtocolMessage = message }; - await Options.Notifications.RedirectToIdentityProvider(redirectToIdentityProviderNotification); - if (redirectToIdentityProviderNotification.HandledResponse) + await Options.Events.RedirectToIdentityProvider(redirectToIdentityProviderContext); + if (redirectToIdentityProviderContext.HandledResponse) { - Logger.LogVerbose(Resources.OIDCH_0034_RedirectToIdentityProviderNotificationHandledResponse); + Logger.LogVerbose(Resources.OIDCH_0034_RedirectToIdentityProviderContextHandledResponse); return; } - else if (redirectToIdentityProviderNotification.Skipped) + else if (redirectToIdentityProviderContext.Skipped) { - Logger.LogVerbose(Resources.OIDCH_0035_RedirectToIdentityProviderNotificationSkipped); + Logger.LogVerbose(Resources.OIDCH_0035_RedirectToIdentityProviderContextSkipped); return; } - message = redirectToIdentityProviderNotification.ProtocolMessage; + message = redirectToIdentityProviderContext.ProtocolMessage; if (Options.AuthenticationMethod == OpenIdConnectAuthenticationMethod.RedirectGet) { @@ -182,7 +182,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect ClientId = Options.ClientId, IssuerAddress = _configuration?.AuthorizationEndpoint ?? string.Empty, RedirectUri = Options.RedirectUri, - // [brentschmaltz] - #215 this should be a property on RedirectToIdentityProviderNotification not on the OIDCMessage. + // [brentschmaltz] - #215 this should be a property on RedirectToIdentityProviderContext not on the OIDCMessage. RequestType = OpenIdConnectRequestType.AuthenticationRequest, Resource = Options.Resource, ResponseType = Options.ResponseType, @@ -220,30 +220,30 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect } } - var redirectToIdentityProviderNotification = - new RedirectToIdentityProviderNotification(Context, Options) + var redirectToIdentityProviderContext = + new RedirectToIdentityProviderContext(Context, Options) { ProtocolMessage = message }; - await Options.Notifications.RedirectToIdentityProvider(redirectToIdentityProviderNotification); - if (redirectToIdentityProviderNotification.HandledResponse) + await Options.Events.RedirectToIdentityProvider(redirectToIdentityProviderContext); + if (redirectToIdentityProviderContext.HandledResponse) { - Logger.LogVerbose(Resources.OIDCH_0034_RedirectToIdentityProviderNotificationHandledResponse); + Logger.LogVerbose(Resources.OIDCH_0034_RedirectToIdentityProviderContextHandledResponse); return true; } - else if (redirectToIdentityProviderNotification.Skipped) + else if (redirectToIdentityProviderContext.Skipped) { - Logger.LogVerbose(Resources.OIDCH_0035_RedirectToIdentityProviderNotificationSkipped); + Logger.LogVerbose(Resources.OIDCH_0035_RedirectToIdentityProviderContextSkipped); return false; } - if (!string.IsNullOrEmpty(redirectToIdentityProviderNotification.ProtocolMessage.State)) + if (!string.IsNullOrEmpty(redirectToIdentityProviderContext.ProtocolMessage.State)) { - properties.Items[OpenIdConnectAuthenticationDefaults.UserstatePropertiesKey] = redirectToIdentityProviderNotification.ProtocolMessage.State; + properties.Items[OpenIdConnectAuthenticationDefaults.UserstatePropertiesKey] = redirectToIdentityProviderContext.ProtocolMessage.State; } - message = redirectToIdentityProviderNotification.ProtocolMessage; + message = redirectToIdentityProviderContext.ProtocolMessage; var redirectUriForCode = message.RedirectUri; if (string.IsNullOrEmpty(redirectUriForCode)) @@ -356,12 +356,12 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect try { - var messageReceivedNotification = await RunMessageReceivedNotificationAsync(message); - if (messageReceivedNotification.HandledResponse) + var messageReceivedContext = await RunMessageReceivedEventAsync(message); + if (messageReceivedContext.HandledResponse) { - return messageReceivedNotification.AuthenticationTicket; + return messageReceivedContext.AuthenticationTicket; } - else if (messageReceivedNotification.Skipped) + else if (messageReceivedContext.Skipped) { return null; } @@ -419,7 +419,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect { Logger.LogError(Resources.OIDCH_0017_ExceptionOccurredWhileProcessingMessage, exception); - // Refresh the configuration for exceptions that may be caused by key rollovers. The user can also request a refresh in the notification. + // Refresh the configuration for exceptions that may be caused by key rollovers. The user can also request a refresh in the event. if (Options.RefreshOnIssuerKeyNotFound && exception.GetType().Equals(typeof(SecurityTokenSignatureKeyNotFoundException))) { if (Options.ConfigurationManager != null) @@ -429,12 +429,12 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect } } - var authenticationFailedNotification = await RunAuthenticationFailedNotificationAsync(message, exception); - if (authenticationFailedNotification.HandledResponse) + var authenticationFailedContext = await RunAuthenticationFailedEventAsync(message, exception); + if (authenticationFailedContext.HandledResponse) { - return authenticationFailedNotification.AuthenticationTicket; + return authenticationFailedContext.AuthenticationTicket; } - else if (authenticationFailedNotification.Skipped) + else if (authenticationFailedContext.Skipped) { return null; } @@ -450,12 +450,12 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect OpenIdConnectTokenEndpointResponse tokenEndpointResponse = null; string idToken = null; - var authorizationCodeReceivedNotification = await RunAuthorizationCodeReceivedNotificationAsync(message, properties, ticket, jwt); - if (authorizationCodeReceivedNotification.HandledResponse) + var authorizationCodeReceivedContext = await RunAuthorizationCodeReceivedEventAsync(message, properties, ticket, jwt); + if (authorizationCodeReceivedContext.HandledResponse) { - return authorizationCodeReceivedNotification.AuthenticationTicket; + return authorizationCodeReceivedContext.AuthenticationTicket; } - else if (authorizationCodeReceivedNotification.Skipped) + else if (authorizationCodeReceivedContext.Skipped) { return null; } @@ -463,15 +463,15 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect // Redeeming authorization code for tokens Logger.LogDebug(Resources.OIDCH_0038_Redeeming_Auth_Code, message.Code); - tokenEndpointResponse = await RedeemAuthorizationCodeAsync(message.Code, authorizationCodeReceivedNotification.RedirectUri); + tokenEndpointResponse = await RedeemAuthorizationCodeAsync(message.Code, authorizationCodeReceivedContext.RedirectUri); idToken = tokenEndpointResponse.Message.IdToken; - var authorizationCodeRedeemedNotification = await RunAuthorizationCodeRedeemedNotificationAsync(message, tokenEndpointResponse); - if (authorizationCodeRedeemedNotification.HandledResponse) + var authorizationCodeRedeemedContext = await RunAuthorizationCodeRedeemedEventAsync(message, tokenEndpointResponse); + if (authorizationCodeRedeemedContext.HandledResponse) { - return authorizationCodeRedeemedNotification.AuthenticationTicket; + return authorizationCodeRedeemedContext.AuthenticationTicket; } - else if (authorizationCodeRedeemedNotification.Skipped) + else if (authorizationCodeRedeemedContext.Skipped) { return null; } @@ -490,12 +490,12 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect ticket = await GetUserInformationAsync(properties, tokenEndpointResponse.Message, ticket); } - var securityTokenValidatedNotification = await RunSecurityTokenValidatedNotificationAsync(message, ticket); - if (securityTokenValidatedNotification.HandledResponse) + var securityTokenValidatedContext = await RunSecurityTokenValidatedEventAsync(message, ticket); + if (securityTokenValidatedContext.HandledResponse) { - return securityTokenValidatedNotification.AuthenticationTicket; + return securityTokenValidatedContext.AuthenticationTicket; } - else if (securityTokenValidatedNotification.Skipped) + else if (securityTokenValidatedContext.Skipped) { return null; } @@ -508,12 +508,12 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect AuthenticationTicket ticket = null; JwtSecurityToken jwt = null; - var securityTokenReceivedNotification = await RunSecurityTokenReceivedNotificationAsync(message); - if (securityTokenReceivedNotification.HandledResponse) + var securityTokenReceivedContext = await RunSecurityTokenReceivedEventAsync(message); + if (securityTokenReceivedContext.HandledResponse) { - return securityTokenReceivedNotification.AuthenticationTicket; + return securityTokenReceivedContext.AuthenticationTicket; } - else if (securityTokenReceivedNotification.Skipped) + else if (securityTokenReceivedContext.Skipped) { return null; } @@ -523,24 +523,24 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect await ValidateOpenIdConnectProtocolAsync(jwt, message); - var securityTokenValidatedNotification = await RunSecurityTokenValidatedNotificationAsync(message, ticket); - if (securityTokenValidatedNotification.HandledResponse) + var securityTokenValidatedContext = await RunSecurityTokenValidatedEventAsync(message, ticket); + if (securityTokenValidatedContext.HandledResponse) { - return securityTokenValidatedNotification.AuthenticationTicket; + return securityTokenValidatedContext.AuthenticationTicket; } - else if (securityTokenValidatedNotification.Skipped) + else if (securityTokenValidatedContext.Skipped) { return null; } if (message.Code != null) { - var authorizationCodeReceivedNotification = await RunAuthorizationCodeReceivedNotificationAsync(message, properties, ticket, jwt); - if (authorizationCodeReceivedNotification.HandledResponse) + var authorizationCodeReceivedContext = await RunAuthorizationCodeReceivedEventAsync(message, properties, ticket, jwt); + if (authorizationCodeReceivedContext.HandledResponse) { - return authorizationCodeReceivedNotification.AuthenticationTicket; + return authorizationCodeReceivedContext.AuthenticationTicket; } - else if (authorizationCodeReceivedNotification.Skipped) + else if (authorizationCodeReceivedContext.Skipped) { return null; } @@ -745,36 +745,36 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect } } - private async Task> RunMessageReceivedNotificationAsync(OpenIdConnectMessage message) + private async Task> RunMessageReceivedEventAsync(OpenIdConnectMessage message) { Logger.LogDebug(Resources.OIDCH_0001_MessageReceived, message.BuildRedirectUrl()); - var messageReceivedNotification = - new MessageReceivedNotification(Context, Options) + var messageReceivedContext = + new MessageReceivedContext(Context, Options) { ProtocolMessage = message }; - await Options.Notifications.MessageReceived(messageReceivedNotification); - if (messageReceivedNotification.HandledResponse) + await Options.Events.MessageReceived(messageReceivedContext); + if (messageReceivedContext.HandledResponse) { - Logger.LogVerbose(Resources.OIDCH_0002_MessageReceivedNotificationHandledResponse); + Logger.LogVerbose(Resources.OIDCH_0002_MessageReceivedContextHandledResponse); } - else if (messageReceivedNotification.Skipped) + else if (messageReceivedContext.Skipped) { - Logger.LogVerbose(Resources.OIDCH_0003_MessageReceivedNotificationSkipped); + Logger.LogVerbose(Resources.OIDCH_0003_MessageReceivedContextSkipped); } - return messageReceivedNotification; + return messageReceivedContext; } - private async Task RunAuthorizationCodeReceivedNotificationAsync(OpenIdConnectMessage message, AuthenticationProperties properties, AuthenticationTicket ticket, JwtSecurityToken jwt) + private async Task RunAuthorizationCodeReceivedEventAsync(OpenIdConnectMessage message, AuthenticationProperties properties, AuthenticationTicket ticket, JwtSecurityToken jwt) { var redirectUri = properties.Items.ContainsKey(OpenIdConnectAuthenticationDefaults.RedirectUriForCodePropertiesKey) ? properties.Items[OpenIdConnectAuthenticationDefaults.RedirectUriForCodePropertiesKey] : Options.RedirectUri; Logger.LogDebug(Resources.OIDCH_0014_AuthorizationCodeReceived, message.Code); - var authorizationCodeReceivedNotification = new AuthorizationCodeReceivedNotification(Context, Options) + var authorizationCodeReceivedContext = new AuthorizationCodeReceivedContext(Context, Options) { Code = message.Code, ProtocolMessage = message, @@ -783,105 +783,105 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect JwtSecurityToken = jwt }; - await Options.Notifications.AuthorizationCodeReceived(authorizationCodeReceivedNotification); - if (authorizationCodeReceivedNotification.HandledResponse) + await Options.Events.AuthorizationCodeReceived(authorizationCodeReceivedContext); + if (authorizationCodeReceivedContext.HandledResponse) { - Logger.LogVerbose(Resources.OIDCH_0015_AuthorizationCodeReceivedNotificationHandledResponse); + Logger.LogVerbose(Resources.OIDCH_0015_AuthorizationCodeReceivedContextHandledResponse); } - else if (authorizationCodeReceivedNotification.Skipped) + else if (authorizationCodeReceivedContext.Skipped) { - Logger.LogVerbose(Resources.OIDCH_0016_AuthorizationCodeReceivedNotificationSkipped); + Logger.LogVerbose(Resources.OIDCH_0016_AuthorizationCodeReceivedContextSkipped); } - return authorizationCodeReceivedNotification; + return authorizationCodeReceivedContext; } - private async Task RunAuthorizationCodeRedeemedNotificationAsync(OpenIdConnectMessage message, OpenIdConnectTokenEndpointResponse tokenEndpointResponse) + private async Task RunAuthorizationCodeRedeemedEventAsync(OpenIdConnectMessage message, OpenIdConnectTokenEndpointResponse tokenEndpointResponse) { Logger.LogDebug(Resources.OIDCH_0042_AuthorizationCodeRedeemed, message.Code); - var authorizationCodeRedeemedNotification = new AuthorizationCodeRedeemedNotification(Context, Options) + var authorizationCodeRedeemedContext = new AuthorizationCodeRedeemedContext(Context, Options) { Code = message.Code, ProtocolMessage = message, TokenEndpointResponse = tokenEndpointResponse }; - await Options.Notifications.AuthorizationCodeRedeemed(authorizationCodeRedeemedNotification); - if (authorizationCodeRedeemedNotification.HandledResponse) + await Options.Events.AuthorizationCodeRedeemed(authorizationCodeRedeemedContext); + if (authorizationCodeRedeemedContext.HandledResponse) { - Logger.LogVerbose(Resources.OIDCH_0043_AuthorizationCodeRedeemedNotificationHandledResponse); + Logger.LogVerbose(Resources.OIDCH_0043_AuthorizationCodeRedeemedContextHandledResponse); } - else if (authorizationCodeRedeemedNotification.Skipped) + else if (authorizationCodeRedeemedContext.Skipped) { - Logger.LogVerbose(Resources.OIDCH_0044_AuthorizationCodeRedeemedNotificationSkipped); + Logger.LogVerbose(Resources.OIDCH_0044_AuthorizationCodeRedeemedContextSkipped); } - return authorizationCodeRedeemedNotification; + return authorizationCodeRedeemedContext; } - private async Task> RunSecurityTokenReceivedNotificationAsync(OpenIdConnectMessage message) + private async Task> RunSecurityTokenReceivedEventAsync(OpenIdConnectMessage message) { Logger.LogDebug(Resources.OIDCH_0020_IdTokenReceived, message.IdToken); - var securityTokenReceivedNotification = - new SecurityTokenReceivedNotification(Context, Options) + var securityTokenReceivedContext = + new SecurityTokenReceivedContext(Context, Options) { ProtocolMessage = message, }; - await Options.Notifications.SecurityTokenReceived(securityTokenReceivedNotification); - if (securityTokenReceivedNotification.HandledResponse) + await Options.Events.SecurityTokenReceived(securityTokenReceivedContext); + if (securityTokenReceivedContext.HandledResponse) { - Logger.LogVerbose(Resources.OIDCH_0008_SecurityTokenReceivedNotificationHandledResponse); + Logger.LogVerbose(Resources.OIDCH_0008_SecurityTokenReceivedContextHandledResponse); } - else if (securityTokenReceivedNotification.Skipped) + else if (securityTokenReceivedContext.Skipped) { - Logger.LogVerbose(Resources.OIDCH_0009_SecurityTokenReceivedNotificationSkipped); + Logger.LogVerbose(Resources.OIDCH_0009_SecurityTokenReceivedContextSkipped); } - return securityTokenReceivedNotification; + return securityTokenReceivedContext; } - private async Task> RunSecurityTokenValidatedNotificationAsync(OpenIdConnectMessage message, AuthenticationTicket ticket) + private async Task> RunSecurityTokenValidatedEventAsync(OpenIdConnectMessage message, AuthenticationTicket ticket) { - var securityTokenValidatedNotification = - new SecurityTokenValidatedNotification(Context, Options) + var securityTokenValidatedContext = + new SecurityTokenValidatedContext(Context, Options) { AuthenticationTicket = ticket, ProtocolMessage = message }; - await Options.Notifications.SecurityTokenValidated(securityTokenValidatedNotification); - if (securityTokenValidatedNotification.HandledResponse) + await Options.Events.SecurityTokenValidated(securityTokenValidatedContext); + if (securityTokenValidatedContext.HandledResponse) { - Logger.LogVerbose(Resources.OIDCH_0012_SecurityTokenValidatedNotificationHandledResponse); + Logger.LogVerbose(Resources.OIDCH_0012_SecurityTokenValidatedContextHandledResponse); } - else if (securityTokenValidatedNotification.Skipped) + else if (securityTokenValidatedContext.Skipped) { - Logger.LogVerbose(Resources.OIDCH_0013_SecurityTokenValidatedNotificationSkipped); + Logger.LogVerbose(Resources.OIDCH_0013_SecurityTokenValidatedContextSkipped); } - return securityTokenValidatedNotification; + return securityTokenValidatedContext; } - private async Task> RunAuthenticationFailedNotificationAsync(OpenIdConnectMessage message, Exception exception) + private async Task> RunAuthenticationFailedEventAsync(OpenIdConnectMessage message, Exception exception) { - var authenticationFailedNotification = - new AuthenticationFailedNotification(Context, Options) + var authenticationFailedContext = + new AuthenticationFailedContext(Context, Options) { ProtocolMessage = message, Exception = exception }; - await Options.Notifications.AuthenticationFailed(authenticationFailedNotification); - if (authenticationFailedNotification.HandledResponse) + await Options.Events.AuthenticationFailed(authenticationFailedContext); + if (authenticationFailedContext.HandledResponse) { - Logger.LogVerbose(Resources.OIDCH_0018_AuthenticationFailedNotificationHandledResponse); + Logger.LogVerbose(Resources.OIDCH_0018_AuthenticationFailedContextHandledResponse); } - else if (authenticationFailedNotification.Skipped) + else if (authenticationFailedContext.Skipped) { - Logger.LogVerbose(Resources.OIDCH_0019_AuthenticationFailedNotificationSkipped); + Logger.LogVerbose(Resources.OIDCH_0019_AuthenticationFailedContextSkipped); } - return authenticationFailedNotification; + return authenticationFailedContext; } private AuthenticationTicket ValidateToken(string idToken, OpenIdConnectMessage message, AuthenticationProperties properties, TokenValidationParameters validationParameters, out JwtSecurityToken jwt) diff --git a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationMiddleware.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationMiddleware.cs index d7d1ea45d3..4ed9fb965c 100644 --- a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationMiddleware.cs @@ -92,9 +92,9 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect } } - if (Options.Notifications == null) + if (Options.Events == null) { - Options.Notifications = new OpenIdConnectAuthenticationNotifications(); + Options.Events = new OpenIdConnectAuthenticationEvents(); } if (string.IsNullOrEmpty(Options.TokenValidationParameters.ValidAudience) && !string.IsNullOrEmpty(Options.ClientId)) @@ -162,7 +162,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect var webRequestHandler = handler as WebRequestHandler; if (webRequestHandler == null) { - throw new InvalidOperationException(Resources.OIDCH_0102_ExceptionValidatorHandlerMismatch); + throw new InvalidOperationException(Resources.OIDCH_0102_Exception_ValidatorHandlerMismatch); } webRequestHandler.ServerCertificateValidationCallback = options.BackchannelCertificateValidator.Validate; } diff --git a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationOptions.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationOptions.cs index 4bdfcca994..045b279cfd 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 OpenIdConnectAuthenticationNotifications Notifications { get; set; } = new OpenIdConnectAuthenticationNotifications(); + public OpenIdConnectAuthenticationEvents 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/Notifications/ITwitterAuthenticationNotifications.cs b/src/Microsoft.AspNet.Authentication.Twitter/Events/ITwitterAuthenticationEvents.cs similarity index 96% rename from src/Microsoft.AspNet.Authentication.Twitter/Notifications/ITwitterAuthenticationNotifications.cs rename to src/Microsoft.AspNet.Authentication.Twitter/Events/ITwitterAuthenticationEvents.cs index 19fe1b1ccb..556fcc4a8e 100644 --- a/src/Microsoft.AspNet.Authentication.Twitter/Notifications/ITwitterAuthenticationNotifications.cs +++ b/src/Microsoft.AspNet.Authentication.Twitter/Events/ITwitterAuthenticationEvents.cs @@ -8,7 +8,7 @@ namespace Microsoft.AspNet.Authentication.Twitter /// /// Specifies callback methods which the invokes to enable developer control over the authentication process. /> /// - public interface ITwitterAuthenticationNotifications + public interface ITwitterAuthenticationEvents { /// /// Invoked whenever Twitter succesfully authenticates a user diff --git a/src/Microsoft.AspNet.Authentication.Twitter/Notifications/TwitterApplyRedirectContext.cs b/src/Microsoft.AspNet.Authentication.Twitter/Events/TwitterApplyRedirectContext.cs similarity index 100% rename from src/Microsoft.AspNet.Authentication.Twitter/Notifications/TwitterApplyRedirectContext.cs rename to src/Microsoft.AspNet.Authentication.Twitter/Events/TwitterApplyRedirectContext.cs diff --git a/src/Microsoft.AspNet.Authentication.Twitter/Notifications/TwitterAuthenticatedContext.cs b/src/Microsoft.AspNet.Authentication.Twitter/Events/TwitterAuthenticatedContext.cs similarity index 100% rename from src/Microsoft.AspNet.Authentication.Twitter/Notifications/TwitterAuthenticatedContext.cs rename to src/Microsoft.AspNet.Authentication.Twitter/Events/TwitterAuthenticatedContext.cs diff --git a/src/Microsoft.AspNet.Authentication.Twitter/Notifications/TwitterAuthenticationNotifications.cs b/src/Microsoft.AspNet.Authentication.Twitter/Events/TwitterAuthenticationEvents.cs similarity index 90% rename from src/Microsoft.AspNet.Authentication.Twitter/Notifications/TwitterAuthenticationNotifications.cs rename to src/Microsoft.AspNet.Authentication.Twitter/Events/TwitterAuthenticationEvents.cs index 5b7f7948d8..3fcd6fe84b 100644 --- a/src/Microsoft.AspNet.Authentication.Twitter/Notifications/TwitterAuthenticationNotifications.cs +++ b/src/Microsoft.AspNet.Authentication.Twitter/Events/TwitterAuthenticationEvents.cs @@ -7,14 +7,14 @@ using System.Threading.Tasks; namespace Microsoft.AspNet.Authentication.Twitter { /// - /// Default implementation. + /// Default implementation. /// - public class TwitterAuthenticationNotifications : ITwitterAuthenticationNotifications + public class TwitterAuthenticationEvents : ITwitterAuthenticationEvents { /// - /// Initializes a + /// Initializes a /// - public TwitterAuthenticationNotifications() + public TwitterAuthenticationEvents() { OnAuthenticated = context => Task.FromResult(null); OnReturnEndpoint = context => Task.FromResult(null); diff --git a/src/Microsoft.AspNet.Authentication.Twitter/Notifications/TwitterReturnEndpointContext.cs b/src/Microsoft.AspNet.Authentication.Twitter/Events/TwitterReturnEndpointContext.cs similarity index 100% rename from src/Microsoft.AspNet.Authentication.Twitter/Notifications/TwitterReturnEndpointContext.cs rename to src/Microsoft.AspNet.Authentication.Twitter/Events/TwitterReturnEndpointContext.cs diff --git a/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationHandler.cs b/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationHandler.cs index 7435e21875..e3dde58588 100644 --- a/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationHandler.cs @@ -117,20 +117,20 @@ namespace Microsoft.AspNet.Authentication.Twitter protected virtual async Task CreateTicketAsync(ClaimsIdentity identity, AuthenticationProperties properties, AccessToken token) { - var notification = new TwitterAuthenticatedContext(Context, token.UserId, token.ScreenName, token.Token, token.TokenSecret) + var context = new TwitterAuthenticatedContext(Context, token.UserId, token.ScreenName, token.Token, token.TokenSecret) { Principal = new ClaimsPrincipal(identity), Properties = properties }; - await Options.Notifications.Authenticated(notification); + await Options.Events.Authenticated(context); - if (notification.Principal?.Identity == null) + if (context.Principal?.Identity == null) { return null; } - return new AuthenticationTicket(notification.Principal, notification.Properties, Options.AuthenticationScheme); + return new AuthenticationTicket(context.Principal, context.Properties, Options.AuthenticationScheme); } protected override async Task HandleUnauthorizedAsync([NotNull] ChallengeContext context) @@ -157,7 +157,7 @@ namespace Microsoft.AspNet.Authentication.Twitter var redirectContext = new TwitterApplyRedirectContext( Context, Options, properties, twitterAuthenticationEndpoint); - Options.Notifications.ApplyRedirect(redirectContext); + Options.Events.ApplyRedirect(redirectContext); return true; } else @@ -184,7 +184,7 @@ namespace Microsoft.AspNet.Authentication.Twitter }; model.Properties.RedirectUri = null; - await Options.Notifications.ReturnEndpoint(context); + await Options.Events.ReturnEndpoint(context); if (context.SignInScheme != null && context.Principal != null) { diff --git a/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationMiddleware.cs b/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationMiddleware.cs index 79bcef9c8c..1a0d28f736 100644 --- a/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationMiddleware.cs @@ -51,9 +51,9 @@ namespace Microsoft.AspNet.Authentication.Twitter throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Exception_OptionMustBeProvided, nameof(Options.ConsumerKey))); } - if (Options.Notifications == null) + if (Options.Events == null) { - Options.Notifications = new TwitterAuthenticationNotifications(); + Options.Events = new TwitterAuthenticationEvents(); } if (Options.StateDataFormat == null) { diff --git a/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationOptions.cs b/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationOptions.cs index f5d40e8809..cc6d929a99 100644 --- a/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationOptions.cs +++ b/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationOptions.cs @@ -102,9 +102,9 @@ namespace Microsoft.AspNet.Authentication.Twitter public ISecureDataFormat StateDataFormat { get; set; } /// - /// Gets or sets the used to handle authentication events. + /// Gets or sets the used to handle authentication events. /// - public ITwitterAuthenticationNotifications Notifications { get; set; } + public ITwitterAuthenticationEvents Events { get; set; } /// /// Defines whether access tokens should be stored in the diff --git a/src/Microsoft.AspNet.Authentication/Notifications/AuthenticationFailedNotification.cs b/src/Microsoft.AspNet.Authentication/Events/AuthenticationFailedContext.cs similarity index 64% rename from src/Microsoft.AspNet.Authentication/Notifications/AuthenticationFailedNotification.cs rename to src/Microsoft.AspNet.Authentication/Events/AuthenticationFailedContext.cs index 676072238d..33e99076e6 100644 --- a/src/Microsoft.AspNet.Authentication/Notifications/AuthenticationFailedNotification.cs +++ b/src/Microsoft.AspNet.Authentication/Events/AuthenticationFailedContext.cs @@ -6,9 +6,9 @@ using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Authentication { - public class AuthenticationFailedNotification : BaseNotification + public class AuthenticationFailedContext : BaseControlContext { - public AuthenticationFailedNotification(HttpContext context, TOptions options) : base(context, options) + public AuthenticationFailedContext(HttpContext context, TOptions options) : base(context, options) { } diff --git a/src/Microsoft.AspNet.Authentication/Notifications/BaseContext.cs b/src/Microsoft.AspNet.Authentication/Events/BaseContext.cs similarity index 100% rename from src/Microsoft.AspNet.Authentication/Notifications/BaseContext.cs rename to src/Microsoft.AspNet.Authentication/Events/BaseContext.cs diff --git a/src/Microsoft.AspNet.Authentication/Notifications/BaseContext`1.cs b/src/Microsoft.AspNet.Authentication/Events/BaseContext`1.cs similarity index 100% rename from src/Microsoft.AspNet.Authentication/Notifications/BaseContext`1.cs rename to src/Microsoft.AspNet.Authentication/Events/BaseContext`1.cs diff --git a/src/Microsoft.AspNet.Authentication/Notifications/BaseNotification.cs b/src/Microsoft.AspNet.Authentication/Events/BaseControlContext.cs similarity index 67% rename from src/Microsoft.AspNet.Authentication/Notifications/BaseNotification.cs rename to src/Microsoft.AspNet.Authentication/Events/BaseControlContext.cs index 8cd7424244..1f83f062e1 100644 --- a/src/Microsoft.AspNet.Authentication/Notifications/BaseNotification.cs +++ b/src/Microsoft.AspNet.Authentication/Events/BaseControlContext.cs @@ -5,22 +5,22 @@ using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Authentication { - public class BaseNotification : BaseContext + public class BaseControlContext : BaseContext { - protected BaseNotification(HttpContext context, TOptions options) : base(context, options) + protected BaseControlContext(HttpContext context, TOptions options) : base(context, options) { } - public NotificationResultState State { get; set; } + public EventResultState State { get; set; } public bool HandledResponse { - get { return State == NotificationResultState.HandledResponse; } + get { return State == EventResultState.HandledResponse; } } public bool Skipped { - get { return State == NotificationResultState.Skipped; } + get { return State == EventResultState.Skipped; } } /// @@ -30,7 +30,7 @@ namespace Microsoft.AspNet.Authentication /// public void HandleResponse() { - State = NotificationResultState.HandledResponse; + State = EventResultState.HandledResponse; } /// @@ -39,11 +39,11 @@ namespace Microsoft.AspNet.Authentication /// public void SkipToNextMiddleware() { - State = NotificationResultState.Skipped; + State = EventResultState.Skipped; } /// - /// Gets or set the to return if this notification signals it handled the notification. + /// Gets or set the to return if this event signals it handled the event. /// public AuthenticationTicket AuthenticationTicket { get; set; } } diff --git a/src/Microsoft.AspNet.Authentication/Notifications/EndpointContext.cs b/src/Microsoft.AspNet.Authentication/Events/EndpointContext.cs similarity index 100% rename from src/Microsoft.AspNet.Authentication/Notifications/EndpointContext.cs rename to src/Microsoft.AspNet.Authentication/Events/EndpointContext.cs diff --git a/src/Microsoft.AspNet.Authentication/Notifications/EndpointContext`1.cs b/src/Microsoft.AspNet.Authentication/Events/EndpointContext`1.cs similarity index 100% rename from src/Microsoft.AspNet.Authentication/Notifications/EndpointContext`1.cs rename to src/Microsoft.AspNet.Authentication/Events/EndpointContext`1.cs diff --git a/src/Microsoft.AspNet.Authentication/Notifications/NotificationResultState.cs b/src/Microsoft.AspNet.Authentication/Events/EventResultState.cs similarity index 94% rename from src/Microsoft.AspNet.Authentication/Notifications/NotificationResultState.cs rename to src/Microsoft.AspNet.Authentication/Events/EventResultState.cs index 76fb0a7622..c3437ddff6 100644 --- a/src/Microsoft.AspNet.Authentication/Notifications/NotificationResultState.cs +++ b/src/Microsoft.AspNet.Authentication/Events/EventResultState.cs @@ -5,7 +5,7 @@ using System; namespace Microsoft.AspNet.Authentication { - public enum NotificationResultState + public enum EventResultState { /// /// Continue with normal processing. diff --git a/src/Microsoft.AspNet.Authentication/Notifications/MessageReceivedNotification.cs b/src/Microsoft.AspNet.Authentication/Events/MessageReceivedContext.cs similarity index 72% rename from src/Microsoft.AspNet.Authentication/Notifications/MessageReceivedNotification.cs rename to src/Microsoft.AspNet.Authentication/Events/MessageReceivedContext.cs index dc64a7a504..86babe7277 100644 --- a/src/Microsoft.AspNet.Authentication/Notifications/MessageReceivedNotification.cs +++ b/src/Microsoft.AspNet.Authentication/Events/MessageReceivedContext.cs @@ -5,9 +5,9 @@ using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Authentication { - public class MessageReceivedNotification : BaseNotification + public class MessageReceivedContext : BaseControlContext { - public MessageReceivedNotification(HttpContext context, TOptions options) : base(context, options) + public MessageReceivedContext(HttpContext context, TOptions options) : base(context, options) { } diff --git a/src/Microsoft.AspNet.Authentication/Notifications/RedirectFromIdentityProviderNotification.cs b/src/Microsoft.AspNet.Authentication/Events/RedirectFromIdentityProviderContext.cs similarity index 70% rename from src/Microsoft.AspNet.Authentication/Notifications/RedirectFromIdentityProviderNotification.cs rename to src/Microsoft.AspNet.Authentication/Events/RedirectFromIdentityProviderContext.cs index 61387bc910..9de5cd1a00 100644 --- a/src/Microsoft.AspNet.Authentication/Notifications/RedirectFromIdentityProviderNotification.cs +++ b/src/Microsoft.AspNet.Authentication/Events/RedirectFromIdentityProviderContext.cs @@ -5,9 +5,9 @@ using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Authentication { - public class RedirectFromIdentityProviderNotification : BaseNotification + public class RedirectFromIdentityProviderContext : BaseControlContext { - public RedirectFromIdentityProviderNotification(HttpContext context, TOptions options) + public RedirectFromIdentityProviderContext(HttpContext context, TOptions options) : base(context, options) { } diff --git a/src/Microsoft.AspNet.Authentication/Notifications/RedirectToIdentityProviderNotification.cs b/src/Microsoft.AspNet.Authentication/Events/RedirectToIdentityProviderContext.cs similarity index 68% rename from src/Microsoft.AspNet.Authentication/Notifications/RedirectToIdentityProviderNotification.cs rename to src/Microsoft.AspNet.Authentication/Events/RedirectToIdentityProviderContext.cs index be8ac62b46..9b95794745 100644 --- a/src/Microsoft.AspNet.Authentication/Notifications/RedirectToIdentityProviderNotification.cs +++ b/src/Microsoft.AspNet.Authentication/Events/RedirectToIdentityProviderContext.cs @@ -9,13 +9,13 @@ namespace Microsoft.AspNet.Authentication { /// /// When a user configures the to be notified prior to redirecting to an IdentityProvider - /// an instance of is passed to the 'RedirectToIdentityProviderNotification". + /// an instance of is passed to the 'RedirectToIdentityProviderContext". /// /// protocol specific message. /// protocol specific options. - public class RedirectToIdentityProviderNotification : BaseNotification + public class RedirectToIdentityProviderContext : BaseControlContext { - public RedirectToIdentityProviderNotification([NotNull] HttpContext context, [NotNull] TOptions options) : base(context, options) + public RedirectToIdentityProviderContext([NotNull] HttpContext context, [NotNull] TOptions options) : base(context, options) { } diff --git a/src/Microsoft.AspNet.Authentication/Notifications/ReturnEndpointContext.cs b/src/Microsoft.AspNet.Authentication/Events/ReturnEndpointContext.cs similarity index 100% rename from src/Microsoft.AspNet.Authentication/Notifications/ReturnEndpointContext.cs rename to src/Microsoft.AspNet.Authentication/Events/ReturnEndpointContext.cs diff --git a/src/Microsoft.AspNet.Authentication/Notifications/SecurityTokenReceivedNotification.cs b/src/Microsoft.AspNet.Authentication/Events/SecurityTokenReceivedContext.cs similarity index 64% rename from src/Microsoft.AspNet.Authentication/Notifications/SecurityTokenReceivedNotification.cs rename to src/Microsoft.AspNet.Authentication/Events/SecurityTokenReceivedContext.cs index 5e73c1cafe..225f4fd6de 100644 --- a/src/Microsoft.AspNet.Authentication/Notifications/SecurityTokenReceivedNotification.cs +++ b/src/Microsoft.AspNet.Authentication/Events/SecurityTokenReceivedContext.cs @@ -5,9 +5,9 @@ using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Authentication { - public class SecurityTokenReceivedNotification : BaseNotification + public class SecurityTokenReceivedContext : BaseControlContext { - public SecurityTokenReceivedNotification(HttpContext context, TOptions options) : base(context, options) + public SecurityTokenReceivedContext(HttpContext context, TOptions options) : base(context, options) { } diff --git a/src/Microsoft.AspNet.Authentication/Notifications/SecurityTokenValidatedNotification.cs b/src/Microsoft.AspNet.Authentication/Events/SecurityTokenValidatedContext.cs similarity index 60% rename from src/Microsoft.AspNet.Authentication/Notifications/SecurityTokenValidatedNotification.cs rename to src/Microsoft.AspNet.Authentication/Events/SecurityTokenValidatedContext.cs index 12f520d7e5..4acf056a2e 100644 --- a/src/Microsoft.AspNet.Authentication/Notifications/SecurityTokenValidatedNotification.cs +++ b/src/Microsoft.AspNet.Authentication/Events/SecurityTokenValidatedContext.cs @@ -5,9 +5,9 @@ using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Authentication { - public class SecurityTokenValidatedNotification : BaseNotification + public class SecurityTokenValidatedContext : BaseControlContext { - public SecurityTokenValidatedNotification(HttpContext context, TOptions options) : base(context, options) + public SecurityTokenValidatedContext(HttpContext context, TOptions options) : base(context, options) { } diff --git a/test/Microsoft.AspNet.Authentication.Test/Cookies/CookieMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/Cookies/CookieMiddlewareTests.cs index 139006b06e..ffc1f304de 100644 --- a/test/Microsoft.AspNet.Authentication.Test/Cookies/CookieMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/Cookies/CookieMiddlewareTests.cs @@ -341,7 +341,7 @@ namespace Microsoft.AspNet.Authentication.Cookies { options.SystemClock = clock; options.ExpireTimeSpan = TimeSpan.FromMinutes(10); - options.Notifications = new CookieAuthenticationNotifications + options.Events = new CookieAuthenticationEvents { OnValidatePrincipal = ctx => { @@ -372,7 +372,7 @@ namespace Microsoft.AspNet.Authentication.Cookies options.SystemClock = clock; options.ExpireTimeSpan = TimeSpan.FromMinutes(10); options.SlidingExpiration = false; - options.Notifications = new CookieAuthenticationNotifications + options.Events = new CookieAuthenticationEvents { OnValidatePrincipal = ctx => { @@ -402,7 +402,7 @@ namespace Microsoft.AspNet.Authentication.Cookies options.SystemClock = clock; options.ExpireTimeSpan = TimeSpan.FromMinutes(10); options.SlidingExpiration = false; - options.Notifications = new CookieAuthenticationNotifications + options.Events = new CookieAuthenticationEvents { OnValidatePrincipal = ctx => { @@ -448,7 +448,7 @@ namespace Microsoft.AspNet.Authentication.Cookies { options.SystemClock = clock; options.ExpireTimeSpan = TimeSpan.FromMinutes(10); - options.Notifications = new CookieAuthenticationNotifications + options.Events = new CookieAuthenticationEvents { OnValidatePrincipal = ctx => { @@ -495,7 +495,7 @@ namespace Microsoft.AspNet.Authentication.Cookies options.SystemClock = clock; options.ExpireTimeSpan = TimeSpan.FromMinutes(10); options.SlidingExpiration = false; - options.Notifications = new CookieAuthenticationNotifications() + options.Events = new CookieAuthenticationEvents() { OnResponseSignIn = context => { diff --git a/test/Microsoft.AspNet.Authentication.Test/Facebook/FacebookMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/Facebook/FacebookMiddlewareTests.cs index 5cd06921a5..f32aa37547 100644 --- a/test/Microsoft.AspNet.Authentication.Test/Facebook/FacebookMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/Facebook/FacebookMiddlewareTests.cs @@ -43,7 +43,7 @@ namespace Microsoft.AspNet.Authentication.Facebook { options.AppId = "Test App Id"; options.AppSecret = "Test App Secret"; - options.Notifications = new OAuthAuthenticationNotifications + options.Events = new OAuthAuthenticationEvents { OnApplyRedirect = context => { diff --git a/test/Microsoft.AspNet.Authentication.Test/Google/GoogleMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/Google/GoogleMiddlewareTests.cs index e13b051462..afefb49077 100644 --- a/test/Microsoft.AspNet.Authentication.Test/Google/GoogleMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/Google/GoogleMiddlewareTests.cs @@ -198,7 +198,7 @@ namespace Microsoft.AspNet.Authentication.Google { options.ClientId = "Test Id"; options.ClientSecret = "Test Secret"; - options.Notifications = new OAuthAuthenticationNotifications + options.Events = new OAuthAuthenticationEvents { OnApplyRedirect = context => { @@ -414,7 +414,7 @@ namespace Microsoft.AspNet.Authentication.Google return null; } }; - options.Notifications = new OAuthAuthenticationNotifications + options.Events = new OAuthAuthenticationEvents { OnAuthenticated = context => { @@ -455,7 +455,7 @@ namespace Microsoft.AspNet.Authentication.Google options.ClientSecret = "Test Secret"; options.StateDataFormat = stateFormat; options.AccessType = "offline"; - options.Notifications = new OAuthAuthenticationNotifications() + options.Events = new OAuthAuthenticationEvents() { OnAuthenticated = context => { diff --git a/test/Microsoft.AspNet.Authentication.Test/JwtBearer/JwtBearerMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/JwtBearer/JwtBearerMiddlewareTests.cs index a6639e823c..cc125fb4e2 100644 --- a/test/Microsoft.AspNet.Authentication.Test/JwtBearer/JwtBearerMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/JwtBearer/JwtBearerMiddlewareTests.cs @@ -67,7 +67,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer { options.AutomaticAuthentication = true; - options.Notifications.MessageReceived = notification => + options.Events.MessageReceived = context => { var claims = new[] { @@ -76,11 +76,11 @@ namespace Microsoft.AspNet.Authentication.JwtBearer new Claim(ClaimsIdentity.DefaultNameClaimType, "bob") }; - notification.AuthenticationTicket = new AuthenticationTicket( - new ClaimsPrincipal(new ClaimsIdentity(claims, notification.Options.AuthenticationScheme)), - new AuthenticationProperties(), notification.Options.AuthenticationScheme); + context.AuthenticationTicket = new AuthenticationTicket( + new ClaimsPrincipal(new ClaimsIdentity(claims, context.Options.AuthenticationScheme)), + new AuthenticationProperties(), context.Options.AuthenticationScheme); - notification.HandleResponse(); + context.HandleResponse(); return Task.FromResult(null); }; @@ -114,7 +114,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer { options.AutomaticAuthentication = true; - options.Notifications.SecurityTokenReceived = notification => + options.Events.SecurityTokenReceived = context => { var claims = new[] { @@ -123,11 +123,11 @@ namespace Microsoft.AspNet.Authentication.JwtBearer new Claim(ClaimsIdentity.DefaultNameClaimType, "bob") }; - notification.AuthenticationTicket = new AuthenticationTicket( - new ClaimsPrincipal(new ClaimsIdentity(claims, notification.Options.AuthenticationScheme)), - new AuthenticationProperties(), notification.Options.AuthenticationScheme); + context.AuthenticationTicket = new AuthenticationTicket( + new ClaimsPrincipal(new ClaimsIdentity(claims, context.Options.AuthenticationScheme)), + new AuthenticationProperties(), context.Options.AuthenticationScheme); - notification.HandleResponse(); + context.HandleResponse(); return Task.FromResult(null); }; @@ -145,11 +145,11 @@ namespace Microsoft.AspNet.Authentication.JwtBearer { options.AutomaticAuthentication = true; - options.Notifications.SecurityTokenValidated = notification => + options.Events.SecurityTokenValidated = context => { // Retrieve the NameIdentifier claim from the identity // returned by the custom security token validator. - var identity = (ClaimsIdentity) notification.AuthenticationTicket.Principal.Identity; + var identity = (ClaimsIdentity)context.AuthenticationTicket.Principal.Identity; var identifier = identity.FindFirst(ClaimTypes.NameIdentifier); identifier.Value.ShouldBe("Bob le Tout Puissant"); @@ -179,13 +179,13 @@ namespace Microsoft.AspNet.Authentication.JwtBearer { options.AutomaticAuthentication = true; - options.Notifications.MessageReceived = notification => + options.Events.MessageReceived = context => { - notification.Token = "CustomToken"; + context.Token = "CustomToken"; return Task.FromResult(null); }; - options.Notifications.SecurityTokenReceived = notification => + options.Events.SecurityTokenReceived = context => { var claims = new[] { @@ -194,11 +194,11 @@ namespace Microsoft.AspNet.Authentication.JwtBearer new Claim(ClaimsIdentity.DefaultNameClaimType, "bob") }; - notification.AuthenticationTicket = new AuthenticationTicket( - new ClaimsPrincipal(new ClaimsIdentity(claims, notification.Options.AuthenticationScheme)), - new AuthenticationProperties(), notification.Options.AuthenticationScheme); + context.AuthenticationTicket = new AuthenticationTicket( + new ClaimsPrincipal(new ClaimsIdentity(claims, context.Options.AuthenticationScheme)), + new AuthenticationProperties(), context.Options.AuthenticationScheme); - notification.HandleResponse(); + context.HandleResponse(); return Task.FromResult(null); }; @@ -214,7 +214,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer { var server = CreateServer(options => { - options.Notifications.SecurityTokenReceived = notification => + options.Events.SecurityTokenReceived = context => { var claims = new[] { @@ -223,11 +223,11 @@ namespace Microsoft.AspNet.Authentication.JwtBearer new Claim(ClaimsIdentity.DefaultNameClaimType, "bob") }; - notification.AuthenticationTicket = new AuthenticationTicket( - new ClaimsPrincipal(new ClaimsIdentity(claims, notification.Options.AuthenticationScheme)), - new AuthenticationProperties(), notification.Options.AuthenticationScheme); + context.AuthenticationTicket = new AuthenticationTicket( + new ClaimsPrincipal(new ClaimsIdentity(claims, context.Options.AuthenticationScheme)), + new AuthenticationProperties(), context.Options.AuthenticationScheme); - notification.HandleResponse(); + context.HandleResponse(); return Task.FromResult(null); }; @@ -242,7 +242,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer { var server = CreateServer(options => { - options.Notifications.SecurityTokenReceived = notification => + options.Events.SecurityTokenReceived = context => { var claims = new[] { @@ -251,11 +251,11 @@ namespace Microsoft.AspNet.Authentication.JwtBearer new Claim(ClaimsIdentity.DefaultNameClaimType, "bob") }; - notification.AuthenticationTicket = new AuthenticationTicket( - new ClaimsPrincipal(new ClaimsIdentity(claims, notification.Options.AuthenticationScheme)), - new AuthenticationProperties(), notification.Options.AuthenticationScheme); + context.AuthenticationTicket = new AuthenticationTicket( + new ClaimsPrincipal(new ClaimsIdentity(claims, context.Options.AuthenticationScheme)), + new AuthenticationProperties(), context.Options.AuthenticationScheme); - notification.HandleResponse(); + context.HandleResponse(); return Task.FromResult(null); }; diff --git a/test/Microsoft.AspNet.Authentication.Test/MicrosoftAccount/MicrosoftAccountMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/MicrosoftAccount/MicrosoftAccountMiddlewareTests.cs index ee5dcb526a..b469100eee 100644 --- a/test/Microsoft.AspNet.Authentication.Test/MicrosoftAccount/MicrosoftAccountMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/MicrosoftAccount/MicrosoftAccountMiddlewareTests.cs @@ -31,7 +31,7 @@ namespace Microsoft.AspNet.Authentication.Tests.MicrosoftAccount { options.ClientId = "Test Client Id"; options.ClientSecret = "Test Client Secret"; - options.Notifications = new OAuthAuthenticationNotifications + options.Events = new OAuthAuthenticationEvents { OnApplyRedirect = context => { @@ -143,7 +143,7 @@ namespace Microsoft.AspNet.Authentication.Tests.MicrosoftAccount return null; } }; - options.Notifications = new OAuthAuthenticationNotifications + options.Events = new OAuthAuthenticationEvents { OnAuthenticated = context => { diff --git a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectHandlerTests.cs b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectHandlerTests.cs index cef7567f18..80c77ac535 100644 --- a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectHandlerTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectHandlerTests.cs @@ -94,26 +94,26 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect } } - // Setup a notification to check for expected state. - // The state gets set by the runtime after the 'MessageReceivedNotification' + // Setup an event to check for expected state. + // The state gets set by the runtime after the 'MessageReceivedContext' private static void SetStateOptions(OpenIdConnectAuthenticationOptions options) { options.AuthenticationScheme = "OpenIdConnectHandlerTest"; options.ConfigurationManager = TestUtilities.DefaultOpenIdConnectConfigurationManager; options.ClientId = Guid.NewGuid().ToString(); options.StateDataFormat = new AuthenticationPropertiesFormaterKeyValue(); - options.Notifications = new OpenIdConnectAuthenticationNotifications + options.Events = new OpenIdConnectAuthenticationEvents { - AuthorizationCodeRedeemed = notification => + AuthorizationCodeRedeemed = context => { - notification.HandleResponse(); - if (notification.ProtocolMessage.State == null && !notification.ProtocolMessage.Parameters.ContainsKey(ExpectedStateParameter)) + context.HandleResponse(); + if (context.ProtocolMessage.State == null && !context.ProtocolMessage.Parameters.ContainsKey(ExpectedStateParameter)) return Task.FromResult(null); - if (notification.ProtocolMessage.State == null || !notification.ProtocolMessage.Parameters.ContainsKey(ExpectedStateParameter)) - Assert.True(false, "(notification.ProtocolMessage.State=!= null || !notification.ProtocolMessage.Parameters.ContainsKey(expectedState)"); + if (context.ProtocolMessage.State == null || !context.ProtocolMessage.Parameters.ContainsKey(ExpectedStateParameter)) + Assert.True(false, "(context.ProtocolMessage.State=!= null || !context.ProtocolMessage.Parameters.ContainsKey(expectedState)"); - Assert.Equal(notification.ProtocolMessage.State, notification.ProtocolMessage.Parameters[ExpectedStateParameter]); + Assert.Equal(context.ProtocolMessage.State, context.ProtocolMessage.Parameters[ExpectedStateParameter]); return Task.FromResult(null); } }; @@ -274,12 +274,12 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect DefaultOptions(options); options.SecurityTokenValidator = MockSecurityTokenValidator(); options.ProtocolValidator = MockProtocolValidator(); - options.Notifications = - new OpenIdConnectAuthenticationNotifications + options.Events = + new OpenIdConnectAuthenticationEvents { - AuthorizationCodeReceived = (notification) => + AuthorizationCodeReceived = (context) => { - notification.HandleResponse(); + context.HandleResponse(); return Task.FromResult(null); } }; @@ -290,12 +290,12 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect DefaultOptions(options); options.SecurityTokenValidator = MockSecurityTokenValidator(); options.ProtocolValidator = MockProtocolValidator(); - options.Notifications = - new OpenIdConnectAuthenticationNotifications + options.Events = + new OpenIdConnectAuthenticationEvents { - AuthorizationCodeReceived = (notification) => + AuthorizationCodeReceived = (context) => { - notification.SkipToNextMiddleware(); + context.SkipToNextMiddleware(); return Task.FromResult(null); } }; @@ -306,12 +306,12 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect DefaultOptions(options); options.SecurityTokenValidator = MockSecurityTokenValidator(); options.ProtocolValidator = MockProtocolValidator(); - options.Notifications = - new OpenIdConnectAuthenticationNotifications + options.Events = + new OpenIdConnectAuthenticationEvents { - AuthenticationFailed = (notification) => + AuthenticationFailed = (context) => { - notification.HandleResponse(); + context.HandleResponse(); return Task.FromResult(null); } }; @@ -322,12 +322,12 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect DefaultOptions(options); options.SecurityTokenValidator = MockSecurityTokenValidator(); options.ProtocolValidator = MockProtocolValidator(); - options.Notifications = - new OpenIdConnectAuthenticationNotifications + options.Events = + new OpenIdConnectAuthenticationEvents { - AuthenticationFailed = (notification) => + AuthenticationFailed = (context) => { - notification.SkipToNextMiddleware(); + context.SkipToNextMiddleware(); return Task.FromResult(null); } }; @@ -336,12 +336,12 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect private static void MessageReceivedHandledOptions(OpenIdConnectAuthenticationOptions options) { DefaultOptions(options); - options.Notifications = - new OpenIdConnectAuthenticationNotifications + options.Events = + new OpenIdConnectAuthenticationEvents { - MessageReceived = (notification) => + MessageReceived = (context) => { - notification.HandleResponse(); + context.HandleResponse(); return Task.FromResult(null); } }; @@ -352,12 +352,12 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect DefaultOptions(options); options.ResponseType = OpenIdConnectResponseTypes.Code; options.StateDataFormat = new AuthenticationPropertiesFormaterKeyValue(); - options.Notifications = - new OpenIdConnectAuthenticationNotifications + options.Events = + new OpenIdConnectAuthenticationEvents { - AuthorizationCodeRedeemed = (notification) => + AuthorizationCodeRedeemed = (context) => { - notification.HandleResponse(); + context.HandleResponse(); return Task.FromResult(null); } }; @@ -368,12 +368,12 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect DefaultOptions(options); options.ResponseType = OpenIdConnectResponseTypes.Code; options.StateDataFormat = new AuthenticationPropertiesFormaterKeyValue(); - options.Notifications = - new OpenIdConnectAuthenticationNotifications + options.Events = + new OpenIdConnectAuthenticationEvents { - AuthorizationCodeRedeemed = (notification) => + AuthorizationCodeRedeemed = (context) => { - notification.SkipToNextMiddleware(); + context.SkipToNextMiddleware(); return Task.FromResult(null); } }; @@ -387,14 +387,14 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect options.StateDataFormat = new AuthenticationPropertiesFormaterKeyValue(); options.GetClaimsFromUserInfoEndpoint = true; options.SecurityTokenValidator = MockSecurityTokenValidator(); - options.Notifications = - new OpenIdConnectAuthenticationNotifications + options.Events = + new OpenIdConnectAuthenticationEvents { - SecurityTokenValidated = (notification) => + SecurityTokenValidated = (context) => { - var claimValue = notification.AuthenticationTicket.Principal.FindFirst("test claim"); + var claimValue = context.AuthenticationTicket.Principal.FindFirst("test claim"); Assert.Equal(claimValue.Value, "test value"); - notification.HandleResponse(); + context.HandleResponse(); return Task.FromResult(null); } }; @@ -402,12 +402,12 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect private static void MessageReceivedSkippedOptions(OpenIdConnectAuthenticationOptions options) { DefaultOptions(options); - options.Notifications = - new OpenIdConnectAuthenticationNotifications + options.Events = + new OpenIdConnectAuthenticationEvents { - MessageReceived = (notification) => + MessageReceived = (context) => { - notification.SkipToNextMiddleware(); + context.SkipToNextMiddleware(); return Task.FromResult(null); } }; @@ -421,12 +421,12 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect private static void SecurityTokenReceivedHandledOptions(OpenIdConnectAuthenticationOptions options) { DefaultOptions(options); - options.Notifications = - new OpenIdConnectAuthenticationNotifications + options.Events = + new OpenIdConnectAuthenticationEvents { - SecurityTokenReceived = (notification) => + SecurityTokenReceived = (context) => { - notification.HandleResponse(); + context.HandleResponse(); return Task.FromResult(null); } }; @@ -435,12 +435,12 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect private static void SecurityTokenReceivedSkippedOptions(OpenIdConnectAuthenticationOptions options) { DefaultOptions(options); - options.Notifications = - new OpenIdConnectAuthenticationNotifications + options.Events = + new OpenIdConnectAuthenticationEvents { - SecurityTokenReceived = (notification) => + SecurityTokenReceived = (context) => { - notification.SkipToNextMiddleware(); + context.SkipToNextMiddleware(); return Task.FromResult(null); } }; @@ -492,12 +492,12 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect private static void SecurityTokenValidatedHandledOptions(OpenIdConnectAuthenticationOptions options) { SecurityTokenValidatorValidatesAllTokens(options); - options.Notifications = - new OpenIdConnectAuthenticationNotifications + options.Events = + new OpenIdConnectAuthenticationEvents { - SecurityTokenValidated = (notification) => + SecurityTokenValidated = (context) => { - notification.HandleResponse(); + context.HandleResponse(); return Task.FromResult(null); } }; @@ -506,12 +506,12 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect private static void SecurityTokenValidatedSkippedOptions(OpenIdConnectAuthenticationOptions options) { SecurityTokenValidatorValidatesAllTokens(options); - options.Notifications = - new OpenIdConnectAuthenticationNotifications + options.Events = + new OpenIdConnectAuthenticationEvents { - SecurityTokenValidated = (notification) => + SecurityTokenValidated = (context) => { - notification.SkipToNextMiddleware(); + context.SkipToNextMiddleware(); return Task.FromResult(null); } }; diff --git a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareTests.cs index 72c82999bf..e8d724be2a 100644 --- a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareTests.cs @@ -100,7 +100,7 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect } /// - /// Tests RedirectToIdentityProviderNotification replaces the OpenIdConnectMesssage correctly. + /// Tests RedirectToIdentityProviderContext replaces the OpenIdConnectMesssage correctly. /// /// Task [Theory] @@ -130,12 +130,12 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect mockOpenIdConnectMessage.Setup(m => m.CreateAuthenticationRequestUrl()).Returns(ExpectedAuthorizeRequest); mockOpenIdConnectMessage.Setup(m => m.CreateLogoutRequestUrl()).Returns(ExpectedLogoutRequest); options.AutomaticAuthentication = true; - options.Notifications = - new OpenIdConnectAuthenticationNotifications + options.Events = + new OpenIdConnectAuthenticationEvents { - RedirectToIdentityProvider = (notification) => + RedirectToIdentityProvider = (context) => { - notification.ProtocolMessage = mockOpenIdConnectMessage.Object; + context.ProtocolMessage = mockOpenIdConnectMessage.Object; return Task.FromResult(null); } }; @@ -143,8 +143,8 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect /// /// Tests for users who want to add 'state'. There are two ways to do it. - /// 1. Users set 'state' (OpenIdConnectMessage.State) in the notification. The runtime appends to that state. - /// 2. Users add to the AuthenticationProperties (notification.AuthenticationProperties), values will be serialized. + /// 1. Users set 'state' (OpenIdConnectMessage.State) in the event. The runtime appends to that state. + /// 2. Users add to the AuthenticationProperties (context.AuthenticationProperties), values will be serialized. /// /// /// @@ -163,11 +163,11 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect { SetOptions(options, DefaultParameters(new string[] { OpenIdConnectParameterNames.State }), queryValues, stateDataFormat); options.AutomaticAuthentication = challenge.Equals(ChallengeWithOutContext); - options.Notifications = new OpenIdConnectAuthenticationNotifications + options.Events = new OpenIdConnectAuthenticationEvents { - RedirectToIdentityProvider = notification => + RedirectToIdentityProvider = context => { - notification.ProtocolMessage.State = userState; + context.ProtocolMessage.State = userState; return Task.FromResult(null); } @@ -207,21 +207,21 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect } [Fact] - public async Task ChallengeWillUseNotifications() + public async Task ChallengeWillUseEvents() { var queryValues = new ExpectedQueryValues(DefaultAuthority); - var queryValuesSetInNotification = new ExpectedQueryValues(DefaultAuthority); + var queryValuesSetInEvent = new ExpectedQueryValues(DefaultAuthority); var server = CreateServer(options => { SetOptions(options, DefaultParameters(), queryValues); - options.Notifications = new OpenIdConnectAuthenticationNotifications + options.Events = new OpenIdConnectAuthenticationEvents { - RedirectToIdentityProvider = notification => + RedirectToIdentityProvider = context => { - notification.ProtocolMessage.ClientId = queryValuesSetInNotification.ClientId; - notification.ProtocolMessage.RedirectUri = queryValuesSetInNotification.RedirectUri; - notification.ProtocolMessage.Resource = queryValuesSetInNotification.Resource; - notification.ProtocolMessage.Scope = queryValuesSetInNotification.Scope; + context.ProtocolMessage.ClientId = queryValuesSetInEvent.ClientId; + context.ProtocolMessage.RedirectUri = queryValuesSetInEvent.RedirectUri; + context.ProtocolMessage.Resource = queryValuesSetInEvent.Resource; + context.ProtocolMessage.Scope = queryValuesSetInEvent.Scope; return Task.FromResult(null); } }; @@ -229,7 +229,7 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect var transaction = await SendAsync(server, DefaultHost + Challenge); transaction.Response.StatusCode.ShouldBe(HttpStatusCode.Redirect); - queryValuesSetInNotification.CheckValues(transaction.Response.Headers.Location.AbsoluteUri, DefaultParameters()); + queryValuesSetInEvent.CheckValues(transaction.Response.Headers.Location.AbsoluteUri, DefaultParameters()); } private void SetOptions(OpenIdConnectAuthenticationOptions options, List parameters, ExpectedQueryValues queryValues, ISecureDataFormat secureDataFormat = null) diff --git a/test/Microsoft.AspNet.Authentication.Test/Twitter/TwitterMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/Twitter/TwitterMiddlewareTests.cs index c5ad93b502..d837cdaffc 100644 --- a/test/Microsoft.AspNet.Authentication.Test/Twitter/TwitterMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/Twitter/TwitterMiddlewareTests.cs @@ -24,7 +24,7 @@ namespace Microsoft.AspNet.Authentication.Twitter { options.ConsumerKey = "Test Consumer Key"; options.ConsumerSecret = "Test Consumer Secret"; - options.Notifications = new TwitterAuthenticationNotifications + options.Events = new TwitterAuthenticationEvents { OnApplyRedirect = context => {