#47 Rename Notifications to Events and Contexts.

This commit is contained in:
Chris R 2015-09-02 14:09:29 -07:00
parent 0f115f1fda
commit d3ad11a753
68 changed files with 446 additions and 449 deletions

View File

@ -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<string>("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<string>("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<string>("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<string>("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));
}
},
};

View File

@ -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;

View File

@ -22,9 +22,9 @@ namespace Microsoft.AspNet.Authentication.Cookies
ConfigureOptions<CookieAuthenticationOptions> 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))
{

View File

@ -28,7 +28,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
CookieHttpOnly = true;
CookieSecure = CookieSecureOption.SameAsRequest;
SystemClock = new SystemClock();
Notifications = new CookieAuthenticationNotifications();
Events = new CookieAuthenticationEvents();
}
/// <summary>
@ -116,10 +116,10 @@ namespace Microsoft.AspNet.Authentication.Cookies
/// <summary>
/// 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.
/// </summary>
public ICookieAuthenticationNotifications Notifications { get; set; }
public ICookieAuthenticationEvents Events { get; set; }
/// <summary>
/// The TicketDataFormat is used to protect and unprotect the identity and other properties which are stored in the

View File

@ -7,16 +7,16 @@ using System.Threading.Tasks;
namespace Microsoft.AspNet.Authentication.Cookies
{
/// <summary>
/// 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.
/// </summary>
public class CookieAuthenticationNotifications : ICookieAuthenticationNotifications
public class CookieAuthenticationEvents : ICookieAuthenticationEvents
{
/// <summary>
/// Create a new instance of the default notifications.
/// Create a new instance of the default events.
/// </summary>
public CookieAuthenticationNotifications()
public CookieAuthenticationEvents()
{
OnValidatePrincipal = context => Task.FromResult(0);
OnResponseSignIn = context => { };

View File

@ -8,7 +8,7 @@ using Microsoft.AspNet.Http.Authentication;
namespace Microsoft.AspNet.Authentication.Cookies
{
/// <summary>
/// Context object passed to the ICookieAuthenticationNotifications method ResponseSignedIn.
/// Context object passed to the ICookieAuthenticationEvents method ResponseSignedIn.
/// </summary>
public class CookieResponseSignedInContext : BaseContext<CookieAuthenticationOptions>
{

View File

@ -8,7 +8,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
/// <summary>
/// Specifies callback methods which the <see cref="CookieAuthenticationMiddleware"></see> invokes to enable developer control over the authentication process. />
/// </summary>
public interface ICookieAuthenticationNotifications
public interface ICookieAuthenticationEvents
{
/// <summary>
/// Called each time a request principal has been validated by the middleware. By implementing this method the

View File

@ -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)

View File

@ -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?

View File

@ -5,9 +5,9 @@ using Microsoft.AspNet.Http;
namespace Microsoft.AspNet.Authentication.JwtBearer
{
public class AuthenticationChallengeNotification<TOptions> : BaseNotification<TOptions>
public class AuthenticationChallengeContext<TOptions> : BaseControlContext<TOptions>
{
public AuthenticationChallengeNotification(HttpContext context, TOptions options) : base(context, options)
public AuthenticationChallengeContext(HttpContext context, TOptions options) : base(context, options)
{
}
}

View File

@ -13,43 +13,43 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
/// <summary>
/// Jwt bearer token middleware provider
/// </summary>
public class JwtBearerAuthenticationNotifications
public class JwtBearerAuthenticationEvents
{
/// <summary>
/// Initializes a new instance of the <see cref="JwtBearerAuthenticationProvider"/> class
/// </summary>
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);
}
/// <summary>
/// Invoked if exceptions are thrown during request processing. The exceptions will be re-thrown after this event unless suppressed.
/// </summary>
public Func<AuthenticationFailedNotification<HttpContext, JwtBearerAuthenticationOptions>, Task> AuthenticationFailed { get; set; }
public Func<AuthenticationFailedContext<HttpContext, JwtBearerAuthenticationOptions>, Task> AuthenticationFailed { get; set; }
/// <summary>
/// Invoked when a protocol message is first received.
/// </summary>
public Func<MessageReceivedNotification<HttpContext, JwtBearerAuthenticationOptions>, Task> MessageReceived { get; set; }
public Func<MessageReceivedContext<HttpContext, JwtBearerAuthenticationOptions>, Task> MessageReceived { get; set; }
/// <summary>
/// Invoked with the security token that has been extracted from the protocol message.
/// </summary>
public Func<SecurityTokenReceivedNotification<HttpContext, JwtBearerAuthenticationOptions>, Task> SecurityTokenReceived { get; set; }
public Func<SecurityTokenReceivedContext<HttpContext, JwtBearerAuthenticationOptions>, Task> SecurityTokenReceived { get; set; }
/// <summary>
/// Invoked after the security token has passed validation and a ClaimsIdentity has been generated.
/// </summary>
public Func<SecurityTokenValidatedNotification<HttpContext, JwtBearerAuthenticationOptions>, Task> SecurityTokenValidated { get; set; }
public Func<SecurityTokenValidatedContext<HttpContext, JwtBearerAuthenticationOptions>, Task> SecurityTokenValidated { get; set; }
/// <summary>
/// Invoked to apply a challenge sent back to the caller.
/// </summary>
public Func<AuthenticationChallengeNotification<JwtBearerAuthenticationOptions>, Task> ApplyChallenge { get; set; }
public Func<AuthenticationChallengeContext<JwtBearerAuthenticationOptions>, Task> ApplyChallenge { get; set; }
}
}

View File

@ -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<HttpContext, JwtBearerAuthenticationOptions>(Context, Options)
var messageReceivedContext =
new MessageReceivedContext<HttpContext, JwtBearerAuthenticationOptions>(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<HttpContext, JwtBearerAuthenticationOptions>(Context, Options)
var securityTokenReceivedContext =
new SecurityTokenReceivedContext<HttpContext, JwtBearerAuthenticationOptions>(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<HttpContext, JwtBearerAuthenticationOptions>(Context, Options)
var securityTokenValidatedContext = new SecurityTokenValidatedContext<HttpContext, JwtBearerAuthenticationOptions>(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<HttpContext, JwtBearerAuthenticationOptions>(Context, Options)
var authenticationFailedContext =
new AuthenticationFailedContext<HttpContext, JwtBearerAuthenticationOptions>(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<bool> HandleUnauthorizedAsync(ChallengeContext context)
{
Response.StatusCode = 401;
await Options.Notifications.ApplyChallenge(new AuthenticationChallengeNotification<JwtBearerAuthenticationOptions>(Context, Options));
await Options.Events.ApplyChallenge(new AuthenticationChallengeContext<JwtBearerAuthenticationOptions>(Context, Options));
return false;
}

View File

@ -34,9 +34,9 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
ConfigureOptions<JwtBearerAuthenticationOptions> 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))

View File

@ -49,10 +49,10 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
/// <summary>
/// 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.
/// </summary>
public JwtBearerAuthenticationNotifications Notifications { get; set; } = new JwtBearerAuthenticationNotifications();
public JwtBearerAuthenticationEvents Events { get; set; } = new JwtBearerAuthenticationEvents();
/// <summary>
/// The HttpMessageHandler used to retrieve metadata.

View File

@ -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);
}
}
}

View File

@ -10,11 +10,11 @@ namespace Microsoft.AspNet.Authentication.OAuth
/// <summary>
/// Specifies callback methods which the <see cref="OAuthAuthenticationMiddleware"/> invokes to enable developer control over the authentication process.
/// </summary>
public interface IOAuthAuthenticationNotifications
public interface IOAuthAuthenticationEvents
{
/// <summary>
/// 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.
/// </summary>
/// <param name="context">Contains information about the login session.</param>
/// <returns>A <see cref="Task"/> representing the completed operation.</returns>

View File

@ -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
{
/// <summary>
/// Default <see cref="IOAuthAuthenticationNotifications"/> implementation.
/// Default <see cref="IOAuthAuthenticationEvents"/> implementation.
/// </summary>
public class OAuthAuthenticationNotifications : IOAuthAuthenticationNotifications
public class OAuthAuthenticationEvents : IOAuthAuthenticationEvents
{
/// <summary>
/// Gets or sets the function that is invoked when the Authenticated method is invoked.

View File

@ -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<AuthenticationTicket> 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<bool> 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);
}

View File

@ -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)

View File

@ -38,7 +38,7 @@ namespace Microsoft.AspNet.Authentication.OAuth
/// <summary>
/// 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.
/// </summary>
public string UserInformationEndpoint { get; set; }
@ -80,9 +80,9 @@ namespace Microsoft.AspNet.Authentication.OAuth
public HttpMessageHandler BackchannelHttpHandler { get; set; }
/// <summary>
/// Gets or sets the <see cref="IOAuthAuthenticationNotifications"/> used to handle authentication events.
/// Gets or sets the <see cref="IOAuthAuthenticationEvents"/> used to handle authentication events.
/// </summary>
public IOAuthAuthenticationNotifications Notifications { get; set; } = new OAuthAuthenticationNotifications();
public IOAuthAuthenticationEvents Events { get; set; } = new OAuthAuthenticationEvents();
/// <summary>
/// A list of permissions to request.

View File

@ -9,14 +9,14 @@ using System.IdentityModel.Tokens.Jwt;
namespace Microsoft.AspNet.Authentication.OpenIdConnect
{
/// <summary>
/// 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.
/// </summary>
public class AuthorizationCodeReceivedNotification : BaseNotification<OpenIdConnectAuthenticationOptions>
public class AuthorizationCodeReceivedContext : BaseControlContext<OpenIdConnectAuthenticationOptions>
{
/// <summary>
/// Creates a <see cref="AuthorizationCodeReceivedNotification"/>
/// Creates a <see cref="AuthorizationCodeReceivedContext"/>
/// </summary>
public AuthorizationCodeReceivedNotification(HttpContext context, OpenIdConnectAuthenticationOptions options) : base(context, options)
public AuthorizationCodeReceivedContext(HttpContext context, OpenIdConnectAuthenticationOptions options) : base(context, options)
{
}

View File

@ -4,14 +4,14 @@ using Microsoft.IdentityModel.Protocols.OpenIdConnect;
namespace Microsoft.AspNet.Authentication.OpenIdConnect
{
/// <summary>
/// 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.
/// </summary>
public class AuthorizationCodeRedeemedNotification : BaseNotification<OpenIdConnectAuthenticationOptions>
public class AuthorizationCodeRedeemedContext : BaseControlContext<OpenIdConnectAuthenticationOptions>
{
/// <summary>
/// Creates a <see cref="AuthorizationCodeRedeemedNotification"/>
/// Creates a <see cref="AuthorizationCodeRedeemedContext"/>
/// </summary>
public AuthorizationCodeRedeemedNotification(HttpContext context, OpenIdConnectAuthenticationOptions options) : base(context, options)
public AuthorizationCodeRedeemedContext(HttpContext context, OpenIdConnectAuthenticationOptions options) : base(context, options)
{
}

View File

@ -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
{
/// <summary>
/// Specifies events which the <see cref="OpenIdConnectAuthenticationMiddleware" />invokes to enable developer control over the authentication process.
/// </summary>
public class OpenIdConnectAuthenticationEvents
{
/// <summary>
/// Creates a new set of events. Each event has a default no-op behavior unless otherwise documented.
/// </summary>
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);
}
/// <summary>
/// Invoked if exceptions are thrown during request processing. The exceptions will be re-thrown after this event unless suppressed.
/// </summary>
public Func<AuthenticationFailedContext<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>, Task> AuthenticationFailed { get; set; }
/// <summary>
/// Invoked after security token validation if an authorization code is present in the protocol message.
/// </summary>
public Func<AuthorizationCodeReceivedContext, Task> AuthorizationCodeReceived { get; set; }
/// <summary>
/// Invoked after "authorization code" is redeemed for tokens at the token endpoint.
/// </summary>
public Func<AuthorizationCodeRedeemedContext, Task> AuthorizationCodeRedeemed { get; set; }
/// <summary>
/// Invoked when a protocol message is first received.
/// </summary>
public Func<MessageReceivedContext<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>, Task> MessageReceived { get; set; }
/// <summary>
/// Invoked to manipulate redirects to the identity provider for SignIn, SignOut, or Challenge.
/// </summary>
public Func<RedirectToIdentityProviderContext<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>, Task> RedirectToIdentityProvider { get; set; }
/// <summary>
/// Invoked with the security token that has been extracted from the protocol message.
/// </summary>
public Func<SecurityTokenReceivedContext<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>, Task> SecurityTokenReceived { get; set; }
/// <summary>
/// Invoked after the security token has passed validation and a ClaimsIdentity has been generated.
/// </summary>
public Func<SecurityTokenValidatedContext<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>, Task> SecurityTokenValidated { get; set; }
}
}

View File

@ -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
{
/// <summary>
/// Specifies events which the <see cref="OpenIdConnectAuthenticationMiddleware" />invokes to enable developer control over the authentication process.
/// </summary>
public class OpenIdConnectAuthenticationNotifications
{
/// <summary>
/// Creates a new set of notifications. Each notification has a default no-op behavior unless otherwise documented.
/// </summary>
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);
}
/// <summary>
/// Invoked if exceptions are thrown during request processing. The exceptions will be re-thrown after this event unless suppressed.
/// </summary>
public Func<AuthenticationFailedNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>, Task> AuthenticationFailed { get; set; }
/// <summary>
/// Invoked after security token validation if an authorization code is present in the protocol message.
/// </summary>
public Func<AuthorizationCodeReceivedNotification, Task> AuthorizationCodeReceived { get; set; }
/// <summary>
/// Invoked after "authorization code" is redeemed for tokens at the token endpoint.
/// </summary>
public Func<AuthorizationCodeRedeemedNotification, Task> AuthorizationCodeRedeemed { get; set; }
/// <summary>
/// Invoked when a protocol message is first received.
/// </summary>
public Func<MessageReceivedNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>, Task> MessageReceived { get; set; }
/// <summary>
/// Invoked to manipulate redirects to the identity provider for SignIn, SignOut, or Challenge.
/// </summary>
public Func<RedirectToIdentityProviderNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>, Task> RedirectToIdentityProvider { get; set; }
/// <summary>
/// Invoked with the security token that has been extracted from the protocol message.
/// </summary>
public Func<SecurityTokenReceivedNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>, Task> SecurityTokenReceived { get; set; }
/// <summary>
/// Invoked after the security token has passed validation and a ClaimsIdentity has been generated.
/// </summary>
public Func<SecurityTokenValidatedNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>, Task> SecurityTokenValidated { get; set; }
}
}

View File

@ -89,24 +89,24 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
message.PostLogoutRedirectUri = Options.PostLogoutRedirectUri;
}
var redirectToIdentityProviderNotification = new RedirectToIdentityProviderNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>(Context, Options)
var redirectToIdentityProviderContext = new RedirectToIdentityProviderContext<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>(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<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>(Context, Options)
var redirectToIdentityProviderContext =
new RedirectToIdentityProviderContext<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>(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<MessageReceivedNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>> RunMessageReceivedNotificationAsync(OpenIdConnectMessage message)
private async Task<MessageReceivedContext<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>> RunMessageReceivedEventAsync(OpenIdConnectMessage message)
{
Logger.LogDebug(Resources.OIDCH_0001_MessageReceived, message.BuildRedirectUrl());
var messageReceivedNotification =
new MessageReceivedNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>(Context, Options)
var messageReceivedContext =
new MessageReceivedContext<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>(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<AuthorizationCodeReceivedNotification> RunAuthorizationCodeReceivedNotificationAsync(OpenIdConnectMessage message, AuthenticationProperties properties, AuthenticationTicket ticket, JwtSecurityToken jwt)
private async Task<AuthorizationCodeReceivedContext> 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<AuthorizationCodeRedeemedNotification> RunAuthorizationCodeRedeemedNotificationAsync(OpenIdConnectMessage message, OpenIdConnectTokenEndpointResponse tokenEndpointResponse)
private async Task<AuthorizationCodeRedeemedContext> 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<SecurityTokenReceivedNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>> RunSecurityTokenReceivedNotificationAsync(OpenIdConnectMessage message)
private async Task<SecurityTokenReceivedContext<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>> RunSecurityTokenReceivedEventAsync(OpenIdConnectMessage message)
{
Logger.LogDebug(Resources.OIDCH_0020_IdTokenReceived, message.IdToken);
var securityTokenReceivedNotification =
new SecurityTokenReceivedNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>(Context, Options)
var securityTokenReceivedContext =
new SecurityTokenReceivedContext<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>(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<SecurityTokenValidatedNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>> RunSecurityTokenValidatedNotificationAsync(OpenIdConnectMessage message, AuthenticationTicket ticket)
private async Task<SecurityTokenValidatedContext<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>> RunSecurityTokenValidatedEventAsync(OpenIdConnectMessage message, AuthenticationTicket ticket)
{
var securityTokenValidatedNotification =
new SecurityTokenValidatedNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>(Context, Options)
var securityTokenValidatedContext =
new SecurityTokenValidatedContext<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>(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<AuthenticationFailedNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>> RunAuthenticationFailedNotificationAsync(OpenIdConnectMessage message, Exception exception)
private async Task<AuthenticationFailedContext<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>> RunAuthenticationFailedEventAsync(OpenIdConnectMessage message, Exception exception)
{
var authenticationFailedNotification =
new AuthenticationFailedNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>(Context, Options)
var authenticationFailedContext =
new AuthenticationFailedContext<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>(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)

View File

@ -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;
}

View File

@ -160,9 +160,9 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
public bool CacheNonces { get; set; }
/// <summary>
/// Gets or sets the <see cref="OpenIdConnectAuthenticationNotifications"/> to notify when processing OpenIdConnect messages.
/// Gets or sets the <see cref="OpenIdConnectAuthenticationEvents"/> to notify when processing OpenIdConnect messages.
/// </summary>
public OpenIdConnectAuthenticationNotifications Notifications { get; set; } = new OpenIdConnectAuthenticationNotifications();
public OpenIdConnectAuthenticationEvents Events { get; set; } = new OpenIdConnectAuthenticationEvents();
/// <summary>
/// Gets or sets the <see cref="OpenIdConnectProtocolValidator"/> that is used to ensure that the 'id_token' received

View File

@ -8,7 +8,7 @@ namespace Microsoft.AspNet.Authentication.Twitter
/// <summary>
/// Specifies callback methods which the <see cref="TwitterAuthenticationMiddleware"></see> invokes to enable developer control over the authentication process. />
/// </summary>
public interface ITwitterAuthenticationNotifications
public interface ITwitterAuthenticationEvents
{
/// <summary>
/// Invoked whenever Twitter succesfully authenticates a user

View File

@ -7,14 +7,14 @@ using System.Threading.Tasks;
namespace Microsoft.AspNet.Authentication.Twitter
{
/// <summary>
/// Default <see cref="ITwitterAuthenticationNotifications"/> implementation.
/// Default <see cref="ITwitterAuthenticationEvents"/> implementation.
/// </summary>
public class TwitterAuthenticationNotifications : ITwitterAuthenticationNotifications
public class TwitterAuthenticationEvents : ITwitterAuthenticationEvents
{
/// <summary>
/// Initializes a <see cref="TwitterAuthenticationNotifications"/>
/// Initializes a <see cref="TwitterAuthenticationEvents"/>
/// </summary>
public TwitterAuthenticationNotifications()
public TwitterAuthenticationEvents()
{
OnAuthenticated = context => Task.FromResult<object>(null);
OnReturnEndpoint = context => Task.FromResult<object>(null);

View File

@ -117,20 +117,20 @@ namespace Microsoft.AspNet.Authentication.Twitter
protected virtual async Task<AuthenticationTicket> 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<bool> 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)
{

View File

@ -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)
{

View File

@ -102,9 +102,9 @@ namespace Microsoft.AspNet.Authentication.Twitter
public ISecureDataFormat<RequestToken> StateDataFormat { get; set; }
/// <summary>
/// Gets or sets the <see cref="ITwitterAuthenticationNotifications"/> used to handle authentication events.
/// Gets or sets the <see cref="ITwitterAuthenticationEvents"/> used to handle authentication events.
/// </summary>
public ITwitterAuthenticationNotifications Notifications { get; set; }
public ITwitterAuthenticationEvents Events { get; set; }
/// <summary>
/// Defines whether access tokens should be stored in the

View File

@ -6,9 +6,9 @@ using Microsoft.AspNet.Http;
namespace Microsoft.AspNet.Authentication
{
public class AuthenticationFailedNotification<TMessage, TOptions> : BaseNotification<TOptions>
public class AuthenticationFailedContext<TMessage, TOptions> : BaseControlContext<TOptions>
{
public AuthenticationFailedNotification(HttpContext context, TOptions options) : base(context, options)
public AuthenticationFailedContext(HttpContext context, TOptions options) : base(context, options)
{
}

View File

@ -5,22 +5,22 @@ using Microsoft.AspNet.Http;
namespace Microsoft.AspNet.Authentication
{
public class BaseNotification<TOptions> : BaseContext<TOptions>
public class BaseControlContext<TOptions> : BaseContext<TOptions>
{
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; }
}
/// <summary>
@ -30,7 +30,7 @@ namespace Microsoft.AspNet.Authentication
/// </summary>
public void HandleResponse()
{
State = NotificationResultState.HandledResponse;
State = EventResultState.HandledResponse;
}
/// <summary>
@ -39,11 +39,11 @@ namespace Microsoft.AspNet.Authentication
/// </summary>
public void SkipToNextMiddleware()
{
State = NotificationResultState.Skipped;
State = EventResultState.Skipped;
}
/// <summary>
/// Gets or set the <see cref="AuthenticationTicket"/> to return if this notification signals it handled the notification.
/// Gets or set the <see cref="AuthenticationTicket"/> to return if this event signals it handled the event.
/// </summary>
public AuthenticationTicket AuthenticationTicket { get; set; }
}

View File

@ -5,7 +5,7 @@ using System;
namespace Microsoft.AspNet.Authentication
{
public enum NotificationResultState
public enum EventResultState
{
/// <summary>
/// Continue with normal processing.

View File

@ -5,9 +5,9 @@ using Microsoft.AspNet.Http;
namespace Microsoft.AspNet.Authentication
{
public class MessageReceivedNotification<TMessage, TOptions> : BaseNotification<TOptions>
public class MessageReceivedContext<TMessage, TOptions> : BaseControlContext<TOptions>
{
public MessageReceivedNotification(HttpContext context, TOptions options) : base(context, options)
public MessageReceivedContext(HttpContext context, TOptions options) : base(context, options)
{
}

View File

@ -5,9 +5,9 @@ using Microsoft.AspNet.Http;
namespace Microsoft.AspNet.Authentication
{
public class RedirectFromIdentityProviderNotification<TMessage, TOptions> : BaseNotification<TOptions>
public class RedirectFromIdentityProviderContext<TMessage, TOptions> : BaseControlContext<TOptions>
{
public RedirectFromIdentityProviderNotification(HttpContext context, TOptions options)
public RedirectFromIdentityProviderContext(HttpContext context, TOptions options)
: base(context, options)
{
}

View File

@ -9,13 +9,13 @@ namespace Microsoft.AspNet.Authentication
{
/// <summary>
/// When a user configures the <see cref="AuthenticationMiddleware{TOptions}"/> to be notified prior to redirecting to an IdentityProvider
/// an instance of <see cref="RedirectFromIdentityProviderNotification{TMessage, TOptions, TMessage}"/> is passed to the 'RedirectToIdentityProviderNotification".
/// an instance of <see cref="RedirectFromIdentityProviderContext{TMessage, TOptions, TMessage}"/> is passed to the 'RedirectToIdentityProviderContext".
/// </summary>
/// <typeparam name="TMessage">protocol specific message.</typeparam>
/// <typeparam name="TOptions">protocol specific options.</typeparam>
public class RedirectToIdentityProviderNotification<TMessage, TOptions> : BaseNotification<TOptions>
public class RedirectToIdentityProviderContext<TMessage, TOptions> : BaseControlContext<TOptions>
{
public RedirectToIdentityProviderNotification([NotNull] HttpContext context, [NotNull] TOptions options) : base(context, options)
public RedirectToIdentityProviderContext([NotNull] HttpContext context, [NotNull] TOptions options) : base(context, options)
{
}

View File

@ -5,9 +5,9 @@ using Microsoft.AspNet.Http;
namespace Microsoft.AspNet.Authentication
{
public class SecurityTokenReceivedNotification<TMessage, TOptions> : BaseNotification<TOptions>
public class SecurityTokenReceivedContext<TMessage, TOptions> : BaseControlContext<TOptions>
{
public SecurityTokenReceivedNotification(HttpContext context, TOptions options) : base(context, options)
public SecurityTokenReceivedContext(HttpContext context, TOptions options) : base(context, options)
{
}

View File

@ -5,9 +5,9 @@ using Microsoft.AspNet.Http;
namespace Microsoft.AspNet.Authentication
{
public class SecurityTokenValidatedNotification<TMessage, TOptions> : BaseNotification<TOptions>
public class SecurityTokenValidatedContext<TMessage, TOptions> : BaseControlContext<TOptions>
{
public SecurityTokenValidatedNotification(HttpContext context, TOptions options) : base(context, options)
public SecurityTokenValidatedContext(HttpContext context, TOptions options) : base(context, options)
{
}

View File

@ -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 =>
{

View File

@ -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 =>
{

View File

@ -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 =>
{

View File

@ -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<object>(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<object>(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<object>(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<object>(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<object>(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<object>(null);
};

View File

@ -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 =>
{

View File

@ -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<object>(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<object>(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<object>(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<object>(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<object>(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<object>(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<object>(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<object>(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<object>(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<object>(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<object>(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<object>(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<object>(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<object>(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<object>(null);
}
};

View File

@ -100,7 +100,7 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
}
/// <summary>
/// Tests RedirectToIdentityProviderNotification replaces the OpenIdConnectMesssage correctly.
/// Tests RedirectToIdentityProviderContext replaces the OpenIdConnectMesssage correctly.
/// </summary>
/// <returns>Task</returns>
[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<object>(null);
}
};
@ -143,8 +143,8 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
/// <summary>
/// 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.
/// </summary>
/// <param name="userSetsState"></param>
/// <returns></returns>
@ -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<object>(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<object>(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<string> parameters, ExpectedQueryValues queryValues, ISecureDataFormat<AuthenticationProperties> secureDataFormat = null)

View File

@ -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 =>
{