#47 Rename Notifications to Events and Contexts.
This commit is contained in:
parent
0f115f1fda
commit
d3ad11a753
|
|
@ -135,16 +135,16 @@ namespace CookieSample
|
||||||
options.ClaimsIssuer = "OAuth2-Github";
|
options.ClaimsIssuer = "OAuth2-Github";
|
||||||
options.SaveTokensAsClaims = false;
|
options.SaveTokensAsClaims = false;
|
||||||
// Retrieving user information is unique to each provider.
|
// 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
|
// Get the GitHub user
|
||||||
var request = new HttpRequestMessage(HttpMethod.Get, notification.Options.UserInformationEndpoint);
|
var request = new HttpRequestMessage(HttpMethod.Get, context.Options.UserInformationEndpoint);
|
||||||
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", notification.AccessToken);
|
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", context.AccessToken);
|
||||||
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
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();
|
response.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
var user = JObject.Parse(await response.Content.ReadAsStringAsync());
|
var user = JObject.Parse(await response.Content.ReadAsStringAsync());
|
||||||
|
|
@ -152,33 +152,33 @@ namespace CookieSample
|
||||||
var identifier = user.Value<string>("id");
|
var identifier = user.Value<string>("id");
|
||||||
if (!string.IsNullOrEmpty(identifier))
|
if (!string.IsNullOrEmpty(identifier))
|
||||||
{
|
{
|
||||||
notification.Identity.AddClaim(new Claim(
|
context.Identity.AddClaim(new Claim(
|
||||||
ClaimTypes.NameIdentifier, identifier,
|
ClaimTypes.NameIdentifier, identifier,
|
||||||
ClaimValueTypes.String, notification.Options.ClaimsIssuer));
|
ClaimValueTypes.String, context.Options.ClaimsIssuer));
|
||||||
}
|
}
|
||||||
|
|
||||||
var userName = user.Value<string>("login");
|
var userName = user.Value<string>("login");
|
||||||
if (!string.IsNullOrEmpty(userName))
|
if (!string.IsNullOrEmpty(userName))
|
||||||
{
|
{
|
||||||
notification.Identity.AddClaim(new Claim(
|
context.Identity.AddClaim(new Claim(
|
||||||
ClaimsIdentity.DefaultNameClaimType, userName,
|
ClaimsIdentity.DefaultNameClaimType, userName,
|
||||||
ClaimValueTypes.String, notification.Options.ClaimsIssuer));
|
ClaimValueTypes.String, context.Options.ClaimsIssuer));
|
||||||
}
|
}
|
||||||
|
|
||||||
var name = user.Value<string>("name");
|
var name = user.Value<string>("name");
|
||||||
if (!string.IsNullOrEmpty(name))
|
if (!string.IsNullOrEmpty(name))
|
||||||
{
|
{
|
||||||
notification.Identity.AddClaim(new Claim(
|
context.Identity.AddClaim(new Claim(
|
||||||
"urn:github:name", name,
|
"urn:github:name", name,
|
||||||
ClaimValueTypes.String, notification.Options.ClaimsIssuer));
|
ClaimValueTypes.String, context.Options.ClaimsIssuer));
|
||||||
}
|
}
|
||||||
|
|
||||||
var link = user.Value<string>("url");
|
var link = user.Value<string>("url");
|
||||||
if (!string.IsNullOrEmpty(link))
|
if (!string.IsNullOrEmpty(link))
|
||||||
{
|
{
|
||||||
notification.Identity.AddClaim(new Claim(
|
context.Identity.AddClaim(new Claim(
|
||||||
"urn:github:url", link,
|
"urn:github:url", link,
|
||||||
ClaimValueTypes.String, notification.Options.ClaimsIssuer));
|
ClaimValueTypes.String, context.Options.ClaimsIssuer));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
||||||
}
|
}
|
||||||
|
|
||||||
var context = new CookieValidatePrincipalContext(Context, ticket, Options);
|
var context = new CookieValidatePrincipalContext(Context, ticket, Options);
|
||||||
await Options.Notifications.ValidatePrincipal(context);
|
await Options.Events.ValidatePrincipal(context);
|
||||||
|
|
||||||
if (context.Principal == null)
|
if (context.Principal == null)
|
||||||
{
|
{
|
||||||
|
|
@ -132,7 +132,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
||||||
{
|
{
|
||||||
var exceptionContext = new CookieExceptionContext(Context, Options,
|
var exceptionContext = new CookieExceptionContext(Context, Options,
|
||||||
CookieExceptionContext.ExceptionLocation.Authenticate, exception, ticket);
|
CookieExceptionContext.ExceptionLocation.Authenticate, exception, ticket);
|
||||||
Options.Notifications.Exception(exceptionContext);
|
Options.Events.Exception(exceptionContext);
|
||||||
if (exceptionContext.Rethrow)
|
if (exceptionContext.Rethrow)
|
||||||
{
|
{
|
||||||
throw;
|
throw;
|
||||||
|
|
@ -210,7 +210,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
||||||
{
|
{
|
||||||
var exceptionContext = new CookieExceptionContext(Context, Options,
|
var exceptionContext = new CookieExceptionContext(Context, Options,
|
||||||
CookieExceptionContext.ExceptionLocation.FinishResponse, exception, ticket);
|
CookieExceptionContext.ExceptionLocation.FinishResponse, exception, ticket);
|
||||||
Options.Notifications.Exception(exceptionContext);
|
Options.Events.Exception(exceptionContext);
|
||||||
if (exceptionContext.Rethrow)
|
if (exceptionContext.Rethrow)
|
||||||
{
|
{
|
||||||
throw;
|
throw;
|
||||||
|
|
@ -249,7 +249,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
||||||
signInContext.Properties.ExpiresUtc = issuedUtc.Add(Options.ExpireTimeSpan);
|
signInContext.Properties.ExpiresUtc = issuedUtc.Add(Options.ExpireTimeSpan);
|
||||||
}
|
}
|
||||||
|
|
||||||
Options.Notifications.ResponseSignIn(signInContext);
|
Options.Events.ResponseSignIn(signInContext);
|
||||||
|
|
||||||
if (signInContext.Properties.IsPersistent)
|
if (signInContext.Properties.IsPersistent)
|
||||||
{
|
{
|
||||||
|
|
@ -286,7 +286,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
||||||
signInContext.Principal,
|
signInContext.Principal,
|
||||||
signInContext.Properties);
|
signInContext.Properties);
|
||||||
|
|
||||||
Options.Notifications.ResponseSignedIn(signedInContext);
|
Options.Events.ResponseSignedIn(signedInContext);
|
||||||
|
|
||||||
var shouldLoginRedirect = Options.LoginPath.HasValue && OriginalPath == Options.LoginPath;
|
var shouldLoginRedirect = Options.LoginPath.HasValue && OriginalPath == Options.LoginPath;
|
||||||
ApplyHeaders(shouldLoginRedirect);
|
ApplyHeaders(shouldLoginRedirect);
|
||||||
|
|
@ -295,7 +295,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
||||||
{
|
{
|
||||||
var exceptionContext = new CookieExceptionContext(Context, Options,
|
var exceptionContext = new CookieExceptionContext(Context, Options,
|
||||||
CookieExceptionContext.ExceptionLocation.SignIn, exception, ticket);
|
CookieExceptionContext.ExceptionLocation.SignIn, exception, ticket);
|
||||||
Options.Notifications.Exception(exceptionContext);
|
Options.Events.Exception(exceptionContext);
|
||||||
if (exceptionContext.Rethrow)
|
if (exceptionContext.Rethrow)
|
||||||
{
|
{
|
||||||
throw;
|
throw;
|
||||||
|
|
@ -319,7 +319,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
||||||
Options,
|
Options,
|
||||||
cookieOptions);
|
cookieOptions);
|
||||||
|
|
||||||
Options.Notifications.ResponseSignOut(context);
|
Options.Events.ResponseSignOut(context);
|
||||||
|
|
||||||
Options.CookieManager.DeleteCookie(
|
Options.CookieManager.DeleteCookie(
|
||||||
Context,
|
Context,
|
||||||
|
|
@ -333,7 +333,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
||||||
{
|
{
|
||||||
var exceptionContext = new CookieExceptionContext(Context, Options,
|
var exceptionContext = new CookieExceptionContext(Context, Options,
|
||||||
CookieExceptionContext.ExceptionLocation.SignOut, exception, ticket);
|
CookieExceptionContext.ExceptionLocation.SignOut, exception, ticket);
|
||||||
Options.Notifications.Exception(exceptionContext);
|
Options.Events.Exception(exceptionContext);
|
||||||
if (exceptionContext.Rethrow)
|
if (exceptionContext.Rethrow)
|
||||||
{
|
{
|
||||||
throw;
|
throw;
|
||||||
|
|
@ -355,7 +355,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
||||||
&& IsHostRelative(redirectUri))
|
&& IsHostRelative(redirectUri))
|
||||||
{
|
{
|
||||||
var redirectContext = new CookieApplyRedirectContext(Context, Options, 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;
|
Options.AccessDeniedPath;
|
||||||
|
|
||||||
var redirectContext = new CookieApplyRedirectContext(Context, Options, accessDeniedUri);
|
var redirectContext = new CookieApplyRedirectContext(Context, Options, accessDeniedUri);
|
||||||
Options.Notifications.ApplyRedirect(redirectContext);
|
Options.Events.ApplyRedirect(redirectContext);
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
var exceptionContext = new CookieExceptionContext(Context, Options,
|
var exceptionContext = new CookieExceptionContext(Context, Options,
|
||||||
CookieExceptionContext.ExceptionLocation.Forbidden, exception, ticket: null);
|
CookieExceptionContext.ExceptionLocation.Forbidden, exception, ticket: null);
|
||||||
Options.Notifications.Exception(exceptionContext);
|
Options.Events.Exception(exceptionContext);
|
||||||
if (exceptionContext.Rethrow)
|
if (exceptionContext.Rethrow)
|
||||||
{
|
{
|
||||||
throw;
|
throw;
|
||||||
|
|
@ -412,13 +412,13 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
||||||
|
|
||||||
var loginUri = Options.LoginPath + QueryString.Create(Options.ReturnUrlParameter, redirectUri);
|
var loginUri = Options.LoginPath + QueryString.Create(Options.ReturnUrlParameter, redirectUri);
|
||||||
var redirectContext = new CookieApplyRedirectContext(Context, Options, BuildRedirectUri(loginUri));
|
var redirectContext = new CookieApplyRedirectContext(Context, Options, BuildRedirectUri(loginUri));
|
||||||
Options.Notifications.ApplyRedirect(redirectContext);
|
Options.Events.ApplyRedirect(redirectContext);
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
var exceptionContext = new CookieExceptionContext(Context, Options,
|
var exceptionContext = new CookieExceptionContext(Context, Options,
|
||||||
CookieExceptionContext.ExceptionLocation.Unauthorized, exception, ticket: null);
|
CookieExceptionContext.ExceptionLocation.Unauthorized, exception, ticket: null);
|
||||||
Options.Notifications.Exception(exceptionContext);
|
Options.Events.Exception(exceptionContext);
|
||||||
if (exceptionContext.Rethrow)
|
if (exceptionContext.Rethrow)
|
||||||
{
|
{
|
||||||
throw;
|
throw;
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,9 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
||||||
ConfigureOptions<CookieAuthenticationOptions> configureOptions)
|
ConfigureOptions<CookieAuthenticationOptions> configureOptions)
|
||||||
: base(next, options, loggerFactory, urlEncoder, 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))
|
if (String.IsNullOrEmpty(Options.CookieName))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
||||||
CookieHttpOnly = true;
|
CookieHttpOnly = true;
|
||||||
CookieSecure = CookieSecureOption.SameAsRequest;
|
CookieSecure = CookieSecureOption.SameAsRequest;
|
||||||
SystemClock = new SystemClock();
|
SystemClock = new SystemClock();
|
||||||
Notifications = new CookieAuthenticationNotifications();
|
Events = new CookieAuthenticationEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -116,10 +116,10 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The Provider may be assigned to an instance of an object created by the application at startup time. The middleware
|
/// 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.
|
/// If it is not provided a default instance is supplied which does nothing when the methods are called.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ICookieAuthenticationNotifications Notifications { get; set; }
|
public ICookieAuthenticationEvents Events { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The TicketDataFormat is used to protect and unprotect the identity and other properties which are stored in the
|
/// The TicketDataFormat is used to protect and unprotect the identity and other properties which are stored in the
|
||||||
|
|
|
||||||
|
|
@ -7,16 +7,16 @@ using System.Threading.Tasks;
|
||||||
namespace Microsoft.AspNet.Authentication.Cookies
|
namespace Microsoft.AspNet.Authentication.Cookies
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <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
|
/// application only needs to override a few of the interface methods. This may be used as a base class
|
||||||
/// or may be instantiated directly.
|
/// or may be instantiated directly.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class CookieAuthenticationNotifications : ICookieAuthenticationNotifications
|
public class CookieAuthenticationEvents : ICookieAuthenticationEvents
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a new instance of the default notifications.
|
/// Create a new instance of the default events.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public CookieAuthenticationNotifications()
|
public CookieAuthenticationEvents()
|
||||||
{
|
{
|
||||||
OnValidatePrincipal = context => Task.FromResult(0);
|
OnValidatePrincipal = context => Task.FromResult(0);
|
||||||
OnResponseSignIn = context => { };
|
OnResponseSignIn = context => { };
|
||||||
|
|
@ -8,7 +8,7 @@ using Microsoft.AspNet.Http.Authentication;
|
||||||
namespace Microsoft.AspNet.Authentication.Cookies
|
namespace Microsoft.AspNet.Authentication.Cookies
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Context object passed to the ICookieAuthenticationNotifications method ResponseSignedIn.
|
/// Context object passed to the ICookieAuthenticationEvents method ResponseSignedIn.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class CookieResponseSignedInContext : BaseContext<CookieAuthenticationOptions>
|
public class CookieResponseSignedInContext : BaseContext<CookieAuthenticationOptions>
|
||||||
{
|
{
|
||||||
|
|
@ -8,7 +8,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Specifies callback methods which the <see cref="CookieAuthenticationMiddleware"></see> invokes to enable developer control over the authentication process. />
|
/// Specifies callback methods which the <see cref="CookieAuthenticationMiddleware"></see> invokes to enable developer control over the authentication process. />
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface ICookieAuthenticationNotifications
|
public interface ICookieAuthenticationEvents
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called each time a request principal has been validated by the middleware. By implementing this method the
|
/// Called each time a request principal has been validated by the middleware. By implementing this method the
|
||||||
|
|
@ -62,7 +62,7 @@ namespace Microsoft.AspNet.Authentication.Facebook
|
||||||
|
|
||||||
var payload = JObject.Parse(await response.Content.ReadAsStringAsync());
|
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,
|
Properties = properties,
|
||||||
Principal = new ClaimsPrincipal(identity)
|
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));
|
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)
|
private string GenerateAppSecretProof(string accessToken)
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ namespace Microsoft.AspNet.Authentication.Google
|
||||||
|
|
||||||
var payload = JObject.Parse(await response.Content.ReadAsStringAsync());
|
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,
|
Properties = properties,
|
||||||
Principal = new ClaimsPrincipal(identity)
|
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));
|
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?
|
// TODO: Abstract this properties override pattern into the base class?
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,9 @@ using Microsoft.AspNet.Http;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Authentication.JwtBearer
|
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)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -13,43 +13,43 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Jwt bearer token middleware provider
|
/// Jwt bearer token middleware provider
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class JwtBearerAuthenticationNotifications
|
public class JwtBearerAuthenticationEvents
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="JwtBearerAuthenticationProvider"/> class
|
/// Initializes a new instance of the <see cref="JwtBearerAuthenticationProvider"/> class
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public JwtBearerAuthenticationNotifications()
|
public JwtBearerAuthenticationEvents()
|
||||||
{
|
{
|
||||||
ApplyChallenge = notification => { notification.HttpContext.Response.Headers.Append("WWW-Authenticate", notification.Options.Challenge); return Task.FromResult(0); };
|
ApplyChallenge = context => { context.HttpContext.Response.Headers.Append("WWW-Authenticate", context.Options.Challenge); return Task.FromResult(0); };
|
||||||
AuthenticationFailed = notification => Task.FromResult(0);
|
AuthenticationFailed = context => Task.FromResult(0);
|
||||||
MessageReceived = notification => Task.FromResult(0);
|
MessageReceived = context => Task.FromResult(0);
|
||||||
SecurityTokenReceived = notification => Task.FromResult(0);
|
SecurityTokenReceived = context => Task.FromResult(0);
|
||||||
SecurityTokenValidated = notification => Task.FromResult(0);
|
SecurityTokenValidated = context => Task.FromResult(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Invoked if exceptions are thrown during request processing. The exceptions will be re-thrown after this event unless suppressed.
|
/// Invoked if exceptions are thrown during request processing. The exceptions will be re-thrown after this event unless suppressed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Func<AuthenticationFailedNotification<HttpContext, JwtBearerAuthenticationOptions>, Task> AuthenticationFailed { get; set; }
|
public Func<AuthenticationFailedContext<HttpContext, JwtBearerAuthenticationOptions>, Task> AuthenticationFailed { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Invoked when a protocol message is first received.
|
/// Invoked when a protocol message is first received.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Func<MessageReceivedNotification<HttpContext, JwtBearerAuthenticationOptions>, Task> MessageReceived { get; set; }
|
public Func<MessageReceivedContext<HttpContext, JwtBearerAuthenticationOptions>, Task> MessageReceived { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Invoked with the security token that has been extracted from the protocol message.
|
/// Invoked with the security token that has been extracted from the protocol message.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Func<SecurityTokenReceivedNotification<HttpContext, JwtBearerAuthenticationOptions>, Task> SecurityTokenReceived { get; set; }
|
public Func<SecurityTokenReceivedContext<HttpContext, JwtBearerAuthenticationOptions>, Task> SecurityTokenReceived { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Invoked after the security token has passed validation and a ClaimsIdentity has been generated.
|
/// Invoked after the security token has passed validation and a ClaimsIdentity has been generated.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Func<SecurityTokenValidatedNotification<HttpContext, JwtBearerAuthenticationOptions>, Task> SecurityTokenValidated { get; set; }
|
public Func<SecurityTokenValidatedContext<HttpContext, JwtBearerAuthenticationOptions>, Task> SecurityTokenValidated { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Invoked to apply a challenge sent back to the caller.
|
/// Invoked to apply a challenge sent back to the caller.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Func<AuthenticationChallengeNotification<JwtBearerAuthenticationOptions>, Task> ApplyChallenge { get; set; }
|
public Func<AuthenticationChallengeContext<JwtBearerAuthenticationOptions>, Task> ApplyChallenge { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -27,26 +27,26 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Give application opportunity to find from a different location, adjust, or reject token
|
// Give application opportunity to find from a different location, adjust, or reject token
|
||||||
var messageReceivedNotification =
|
var messageReceivedContext =
|
||||||
new MessageReceivedNotification<HttpContext, JwtBearerAuthenticationOptions>(Context, Options)
|
new MessageReceivedContext<HttpContext, JwtBearerAuthenticationOptions>(Context, Options)
|
||||||
{
|
{
|
||||||
ProtocolMessage = Context,
|
ProtocolMessage = Context,
|
||||||
};
|
};
|
||||||
|
|
||||||
// notification can set the token
|
// event can set the token
|
||||||
await Options.Notifications.MessageReceived(messageReceivedNotification);
|
await Options.Events.MessageReceived(messageReceivedContext);
|
||||||
if (messageReceivedNotification.HandledResponse)
|
if (messageReceivedContext.HandledResponse)
|
||||||
{
|
{
|
||||||
return messageReceivedNotification.AuthenticationTicket;
|
return messageReceivedContext.AuthenticationTicket;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (messageReceivedNotification.Skipped)
|
if (messageReceivedContext.Skipped)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If application retrieved token from somewhere else, use that.
|
// If application retrieved token from somewhere else, use that.
|
||||||
token = messageReceivedNotification.Token;
|
token = messageReceivedContext.Token;
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(token))
|
if (string.IsNullOrEmpty(token))
|
||||||
{
|
{
|
||||||
|
|
@ -71,20 +71,20 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
}
|
}
|
||||||
|
|
||||||
// notify user token was received
|
// notify user token was received
|
||||||
var securityTokenReceivedNotification =
|
var securityTokenReceivedContext =
|
||||||
new SecurityTokenReceivedNotification<HttpContext, JwtBearerAuthenticationOptions>(Context, Options)
|
new SecurityTokenReceivedContext<HttpContext, JwtBearerAuthenticationOptions>(Context, Options)
|
||||||
{
|
{
|
||||||
ProtocolMessage = Context,
|
ProtocolMessage = Context,
|
||||||
SecurityToken = token,
|
SecurityToken = token,
|
||||||
};
|
};
|
||||||
|
|
||||||
await Options.Notifications.SecurityTokenReceived(securityTokenReceivedNotification);
|
await Options.Events.SecurityTokenReceived(securityTokenReceivedContext);
|
||||||
if (securityTokenReceivedNotification.HandledResponse)
|
if (securityTokenReceivedContext.HandledResponse)
|
||||||
{
|
{
|
||||||
return securityTokenReceivedNotification.AuthenticationTicket;
|
return securityTokenReceivedContext.AuthenticationTicket;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (securityTokenReceivedNotification.Skipped)
|
if (securityTokenReceivedContext.Skipped)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -117,19 +117,19 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
{
|
{
|
||||||
var principal = validator.ValidateToken(token, validationParameters, out validatedToken);
|
var principal = validator.ValidateToken(token, validationParameters, out validatedToken);
|
||||||
var ticket = new AuthenticationTicket(principal, new AuthenticationProperties(), Options.AuthenticationScheme);
|
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,
|
ProtocolMessage = Context,
|
||||||
AuthenticationTicket = ticket
|
AuthenticationTicket = ticket
|
||||||
};
|
};
|
||||||
|
|
||||||
await Options.Notifications.SecurityTokenValidated(securityTokenValidatedNotification);
|
await Options.Events.SecurityTokenValidated(securityTokenValidatedContext);
|
||||||
if (securityTokenValidatedNotification.HandledResponse)
|
if (securityTokenValidatedContext.HandledResponse)
|
||||||
{
|
{
|
||||||
return securityTokenValidatedNotification.AuthenticationTicket;
|
return securityTokenValidatedContext.AuthenticationTicket;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (securityTokenValidatedNotification.Skipped)
|
if (securityTokenValidatedContext.Skipped)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -144,26 +144,26 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
{
|
{
|
||||||
Logger.LogError("Exception occurred while processing message", ex);
|
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)))
|
if (Options.RefreshOnIssuerKeyNotFound && ex.GetType().Equals(typeof(SecurityTokenSignatureKeyNotFoundException)))
|
||||||
{
|
{
|
||||||
Options.ConfigurationManager.RequestRefresh();
|
Options.ConfigurationManager.RequestRefresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
var authenticationFailedNotification =
|
var authenticationFailedContext =
|
||||||
new AuthenticationFailedNotification<HttpContext, JwtBearerAuthenticationOptions>(Context, Options)
|
new AuthenticationFailedContext<HttpContext, JwtBearerAuthenticationOptions>(Context, Options)
|
||||||
{
|
{
|
||||||
ProtocolMessage = Context,
|
ProtocolMessage = Context,
|
||||||
Exception = ex
|
Exception = ex
|
||||||
};
|
};
|
||||||
|
|
||||||
await Options.Notifications.AuthenticationFailed(authenticationFailedNotification);
|
await Options.Events.AuthenticationFailed(authenticationFailedContext);
|
||||||
if (authenticationFailedNotification.HandledResponse)
|
if (authenticationFailedContext.HandledResponse)
|
||||||
{
|
{
|
||||||
return authenticationFailedNotification.AuthenticationTicket;
|
return authenticationFailedContext.AuthenticationTicket;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (authenticationFailedNotification.Skipped)
|
if (authenticationFailedContext.Skipped)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -175,7 +175,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
protected override async Task<bool> HandleUnauthorizedAsync(ChallengeContext context)
|
protected override async Task<bool> HandleUnauthorizedAsync(ChallengeContext context)
|
||||||
{
|
{
|
||||||
Response.StatusCode = 401;
|
Response.StatusCode = 401;
|
||||||
await Options.Notifications.ApplyChallenge(new AuthenticationChallengeNotification<JwtBearerAuthenticationOptions>(Context, Options));
|
await Options.Events.ApplyChallenge(new AuthenticationChallengeContext<JwtBearerAuthenticationOptions>(Context, Options));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,9 +34,9 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
ConfigureOptions<JwtBearerAuthenticationOptions> configureOptions)
|
ConfigureOptions<JwtBearerAuthenticationOptions> configureOptions)
|
||||||
: base(next, options, loggerFactory, encoder, 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))
|
if (string.IsNullOrEmpty(Options.TokenValidationParameters.ValidAudience) && !string.IsNullOrEmpty(Options.Audience))
|
||||||
|
|
|
||||||
|
|
@ -49,10 +49,10 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The object provided by the application to process events raised by the bearer authentication middleware.
|
/// 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.
|
/// and assign delegates only to the events it wants to process.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public JwtBearerAuthenticationNotifications Notifications { get; set; } = new JwtBearerAuthenticationNotifications();
|
public JwtBearerAuthenticationEvents Events { get; set; } = new JwtBearerAuthenticationEvents();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The HttpMessageHandler used to retrieve metadata.
|
/// The HttpMessageHandler used to retrieve metadata.
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ namespace Microsoft.AspNet.Authentication.MicrosoftAccount
|
||||||
|
|
||||||
var payload = JObject.Parse(await response.Content.ReadAsStringAsync());
|
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,
|
Properties = properties,
|
||||||
Principal = new ClaimsPrincipal(identity)
|
Principal = new ClaimsPrincipal(identity)
|
||||||
|
|
@ -54,9 +54,9 @@ namespace Microsoft.AspNet.Authentication.MicrosoftAccount
|
||||||
identity.AddClaim(new Claim(ClaimTypes.Email, email, ClaimValueTypes.String, Options.ClaimsIssuer));
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,11 @@ namespace Microsoft.AspNet.Authentication.OAuth
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Specifies callback methods which the <see cref="OAuthAuthenticationMiddleware"/> invokes to enable developer control over the authentication process.
|
/// Specifies callback methods which the <see cref="OAuthAuthenticationMiddleware"/> invokes to enable developer control over the authentication process.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IOAuthAuthenticationNotifications
|
public interface IOAuthAuthenticationEvents
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Invoked after the provider successfully authenticates a user. This can be used to retrieve user information.
|
/// 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>
|
/// </summary>
|
||||||
/// <param name="context">Contains information about the login session.</param>
|
/// <param name="context">Contains information about the login session.</param>
|
||||||
/// <returns>A <see cref="Task"/> representing the completed operation.</returns>
|
/// <returns>A <see cref="Task"/> representing the completed operation.</returns>
|
||||||
|
|
@ -2,16 +2,14 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Security.Claims;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Http.Authentication;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Authentication.OAuth
|
namespace Microsoft.AspNet.Authentication.OAuth
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Default <see cref="IOAuthAuthenticationNotifications"/> implementation.
|
/// Default <see cref="IOAuthAuthenticationEvents"/> implementation.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class OAuthAuthenticationNotifications : IOAuthAuthenticationNotifications
|
public class OAuthAuthenticationEvents : IOAuthAuthenticationEvents
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the function that is invoked when the Authenticated method is invoked.
|
/// Gets or sets the function that is invoked when the Authenticated method is invoked.
|
||||||
|
|
@ -57,7 +57,7 @@ namespace Microsoft.AspNet.Authentication.OAuth
|
||||||
};
|
};
|
||||||
ticket.Properties.RedirectUri = null;
|
ticket.Properties.RedirectUri = null;
|
||||||
|
|
||||||
await Options.Notifications.ReturnEndpoint(context);
|
await Options.Events.ReturnEndpoint(context);
|
||||||
|
|
||||||
if (context.SignInScheme != null && context.Principal != null)
|
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)
|
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),
|
Principal = new ClaimsPrincipal(identity),
|
||||||
Properties = properties
|
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 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)
|
protected override Task<bool> HandleUnauthorizedAsync([NotNull] ChallengeContext context)
|
||||||
|
|
@ -215,7 +215,7 @@ namespace Microsoft.AspNet.Authentication.OAuth
|
||||||
var redirectContext = new OAuthApplyRedirectContext(
|
var redirectContext = new OAuthApplyRedirectContext(
|
||||||
Context, Options,
|
Context, Options,
|
||||||
properties, authorizationEndpoint);
|
properties, authorizationEndpoint);
|
||||||
Options.Notifications.ApplyRedirect(redirectContext);
|
Options.Events.ApplyRedirect(redirectContext);
|
||||||
return Task.FromResult(true);
|
return Task.FromResult(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -63,9 +63,9 @@ namespace Microsoft.AspNet.Authentication.OAuth
|
||||||
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Exception_OptionMustBeProvided, nameof(Options.TokenEndpoint)));
|
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)
|
if (Options.StateDataFormat == null)
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ namespace Microsoft.AspNet.Authentication.OAuth
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the URI the middleware will access to obtain the user information.
|
/// 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
|
/// 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>
|
/// </summary>
|
||||||
public string UserInformationEndpoint { get; set; }
|
public string UserInformationEndpoint { get; set; }
|
||||||
|
|
||||||
|
|
@ -80,9 +80,9 @@ namespace Microsoft.AspNet.Authentication.OAuth
|
||||||
public HttpMessageHandler BackchannelHttpHandler { get; set; }
|
public HttpMessageHandler BackchannelHttpHandler { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
public IOAuthAuthenticationNotifications Notifications { get; set; } = new OAuthAuthenticationNotifications();
|
public IOAuthAuthenticationEvents Events { get; set; } = new OAuthAuthenticationEvents();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A list of permissions to request.
|
/// A list of permissions to request.
|
||||||
|
|
|
||||||
|
|
@ -9,14 +9,14 @@ using System.IdentityModel.Tokens.Jwt;
|
||||||
namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
public class AuthorizationCodeReceivedNotification : BaseNotification<OpenIdConnectAuthenticationOptions>
|
public class AuthorizationCodeReceivedContext : BaseControlContext<OpenIdConnectAuthenticationOptions>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a <see cref="AuthorizationCodeReceivedNotification"/>
|
/// Creates a <see cref="AuthorizationCodeReceivedContext"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public AuthorizationCodeReceivedNotification(HttpContext context, OpenIdConnectAuthenticationOptions options) : base(context, options)
|
public AuthorizationCodeReceivedContext(HttpContext context, OpenIdConnectAuthenticationOptions options) : base(context, options)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -4,14 +4,14 @@ using Microsoft.IdentityModel.Protocols.OpenIdConnect;
|
||||||
namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
public class AuthorizationCodeRedeemedNotification : BaseNotification<OpenIdConnectAuthenticationOptions>
|
public class AuthorizationCodeRedeemedContext : BaseControlContext<OpenIdConnectAuthenticationOptions>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a <see cref="AuthorizationCodeRedeemedNotification"/>
|
/// Creates a <see cref="AuthorizationCodeRedeemedContext"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public AuthorizationCodeRedeemedNotification(HttpContext context, OpenIdConnectAuthenticationOptions options) : base(context, options)
|
public AuthorizationCodeRedeemedContext(HttpContext context, OpenIdConnectAuthenticationOptions options) : base(context, options)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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; }
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -89,24 +89,24 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
message.PostLogoutRedirectUri = Options.PostLogoutRedirectUri;
|
message.PostLogoutRedirectUri = Options.PostLogoutRedirectUri;
|
||||||
}
|
}
|
||||||
|
|
||||||
var redirectToIdentityProviderNotification = new RedirectToIdentityProviderNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>(Context, Options)
|
var redirectToIdentityProviderContext = new RedirectToIdentityProviderContext<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>(Context, Options)
|
||||||
{
|
{
|
||||||
ProtocolMessage = message
|
ProtocolMessage = message
|
||||||
};
|
};
|
||||||
|
|
||||||
await Options.Notifications.RedirectToIdentityProvider(redirectToIdentityProviderNotification);
|
await Options.Events.RedirectToIdentityProvider(redirectToIdentityProviderContext);
|
||||||
if (redirectToIdentityProviderNotification.HandledResponse)
|
if (redirectToIdentityProviderContext.HandledResponse)
|
||||||
{
|
{
|
||||||
Logger.LogVerbose(Resources.OIDCH_0034_RedirectToIdentityProviderNotificationHandledResponse);
|
Logger.LogVerbose(Resources.OIDCH_0034_RedirectToIdentityProviderContextHandledResponse);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (redirectToIdentityProviderNotification.Skipped)
|
else if (redirectToIdentityProviderContext.Skipped)
|
||||||
{
|
{
|
||||||
Logger.LogVerbose(Resources.OIDCH_0035_RedirectToIdentityProviderNotificationSkipped);
|
Logger.LogVerbose(Resources.OIDCH_0035_RedirectToIdentityProviderContextSkipped);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
message = redirectToIdentityProviderNotification.ProtocolMessage;
|
message = redirectToIdentityProviderContext.ProtocolMessage;
|
||||||
|
|
||||||
if (Options.AuthenticationMethod == OpenIdConnectAuthenticationMethod.RedirectGet)
|
if (Options.AuthenticationMethod == OpenIdConnectAuthenticationMethod.RedirectGet)
|
||||||
{
|
{
|
||||||
|
|
@ -182,7 +182,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
ClientId = Options.ClientId,
|
ClientId = Options.ClientId,
|
||||||
IssuerAddress = _configuration?.AuthorizationEndpoint ?? string.Empty,
|
IssuerAddress = _configuration?.AuthorizationEndpoint ?? string.Empty,
|
||||||
RedirectUri = Options.RedirectUri,
|
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,
|
RequestType = OpenIdConnectRequestType.AuthenticationRequest,
|
||||||
Resource = Options.Resource,
|
Resource = Options.Resource,
|
||||||
ResponseType = Options.ResponseType,
|
ResponseType = Options.ResponseType,
|
||||||
|
|
@ -220,30 +220,30 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var redirectToIdentityProviderNotification =
|
var redirectToIdentityProviderContext =
|
||||||
new RedirectToIdentityProviderNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>(Context, Options)
|
new RedirectToIdentityProviderContext<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>(Context, Options)
|
||||||
{
|
{
|
||||||
ProtocolMessage = message
|
ProtocolMessage = message
|
||||||
};
|
};
|
||||||
|
|
||||||
await Options.Notifications.RedirectToIdentityProvider(redirectToIdentityProviderNotification);
|
await Options.Events.RedirectToIdentityProvider(redirectToIdentityProviderContext);
|
||||||
if (redirectToIdentityProviderNotification.HandledResponse)
|
if (redirectToIdentityProviderContext.HandledResponse)
|
||||||
{
|
{
|
||||||
Logger.LogVerbose(Resources.OIDCH_0034_RedirectToIdentityProviderNotificationHandledResponse);
|
Logger.LogVerbose(Resources.OIDCH_0034_RedirectToIdentityProviderContextHandledResponse);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (redirectToIdentityProviderNotification.Skipped)
|
else if (redirectToIdentityProviderContext.Skipped)
|
||||||
{
|
{
|
||||||
Logger.LogVerbose(Resources.OIDCH_0035_RedirectToIdentityProviderNotificationSkipped);
|
Logger.LogVerbose(Resources.OIDCH_0035_RedirectToIdentityProviderContextSkipped);
|
||||||
return false;
|
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;
|
var redirectUriForCode = message.RedirectUri;
|
||||||
if (string.IsNullOrEmpty(redirectUriForCode))
|
if (string.IsNullOrEmpty(redirectUriForCode))
|
||||||
|
|
@ -356,12 +356,12 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var messageReceivedNotification = await RunMessageReceivedNotificationAsync(message);
|
var messageReceivedContext = await RunMessageReceivedEventAsync(message);
|
||||||
if (messageReceivedNotification.HandledResponse)
|
if (messageReceivedContext.HandledResponse)
|
||||||
{
|
{
|
||||||
return messageReceivedNotification.AuthenticationTicket;
|
return messageReceivedContext.AuthenticationTicket;
|
||||||
}
|
}
|
||||||
else if (messageReceivedNotification.Skipped)
|
else if (messageReceivedContext.Skipped)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -419,7 +419,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
{
|
{
|
||||||
Logger.LogError(Resources.OIDCH_0017_ExceptionOccurredWhileProcessingMessage, exception);
|
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.RefreshOnIssuerKeyNotFound && exception.GetType().Equals(typeof(SecurityTokenSignatureKeyNotFoundException)))
|
||||||
{
|
{
|
||||||
if (Options.ConfigurationManager != null)
|
if (Options.ConfigurationManager != null)
|
||||||
|
|
@ -429,12 +429,12 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var authenticationFailedNotification = await RunAuthenticationFailedNotificationAsync(message, exception);
|
var authenticationFailedContext = await RunAuthenticationFailedEventAsync(message, exception);
|
||||||
if (authenticationFailedNotification.HandledResponse)
|
if (authenticationFailedContext.HandledResponse)
|
||||||
{
|
{
|
||||||
return authenticationFailedNotification.AuthenticationTicket;
|
return authenticationFailedContext.AuthenticationTicket;
|
||||||
}
|
}
|
||||||
else if (authenticationFailedNotification.Skipped)
|
else if (authenticationFailedContext.Skipped)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -450,12 +450,12 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
|
|
||||||
OpenIdConnectTokenEndpointResponse tokenEndpointResponse = null;
|
OpenIdConnectTokenEndpointResponse tokenEndpointResponse = null;
|
||||||
string idToken = null;
|
string idToken = null;
|
||||||
var authorizationCodeReceivedNotification = await RunAuthorizationCodeReceivedNotificationAsync(message, properties, ticket, jwt);
|
var authorizationCodeReceivedContext = await RunAuthorizationCodeReceivedEventAsync(message, properties, ticket, jwt);
|
||||||
if (authorizationCodeReceivedNotification.HandledResponse)
|
if (authorizationCodeReceivedContext.HandledResponse)
|
||||||
{
|
{
|
||||||
return authorizationCodeReceivedNotification.AuthenticationTicket;
|
return authorizationCodeReceivedContext.AuthenticationTicket;
|
||||||
}
|
}
|
||||||
else if (authorizationCodeReceivedNotification.Skipped)
|
else if (authorizationCodeReceivedContext.Skipped)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -463,15 +463,15 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
// Redeeming authorization code for tokens
|
// Redeeming authorization code for tokens
|
||||||
Logger.LogDebug(Resources.OIDCH_0038_Redeeming_Auth_Code, message.Code);
|
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;
|
idToken = tokenEndpointResponse.Message.IdToken;
|
||||||
|
|
||||||
var authorizationCodeRedeemedNotification = await RunAuthorizationCodeRedeemedNotificationAsync(message, tokenEndpointResponse);
|
var authorizationCodeRedeemedContext = await RunAuthorizationCodeRedeemedEventAsync(message, tokenEndpointResponse);
|
||||||
if (authorizationCodeRedeemedNotification.HandledResponse)
|
if (authorizationCodeRedeemedContext.HandledResponse)
|
||||||
{
|
{
|
||||||
return authorizationCodeRedeemedNotification.AuthenticationTicket;
|
return authorizationCodeRedeemedContext.AuthenticationTicket;
|
||||||
}
|
}
|
||||||
else if (authorizationCodeRedeemedNotification.Skipped)
|
else if (authorizationCodeRedeemedContext.Skipped)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -490,12 +490,12 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
ticket = await GetUserInformationAsync(properties, tokenEndpointResponse.Message, ticket);
|
ticket = await GetUserInformationAsync(properties, tokenEndpointResponse.Message, ticket);
|
||||||
}
|
}
|
||||||
|
|
||||||
var securityTokenValidatedNotification = await RunSecurityTokenValidatedNotificationAsync(message, ticket);
|
var securityTokenValidatedContext = await RunSecurityTokenValidatedEventAsync(message, ticket);
|
||||||
if (securityTokenValidatedNotification.HandledResponse)
|
if (securityTokenValidatedContext.HandledResponse)
|
||||||
{
|
{
|
||||||
return securityTokenValidatedNotification.AuthenticationTicket;
|
return securityTokenValidatedContext.AuthenticationTicket;
|
||||||
}
|
}
|
||||||
else if (securityTokenValidatedNotification.Skipped)
|
else if (securityTokenValidatedContext.Skipped)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -508,12 +508,12 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
AuthenticationTicket ticket = null;
|
AuthenticationTicket ticket = null;
|
||||||
JwtSecurityToken jwt = null;
|
JwtSecurityToken jwt = null;
|
||||||
|
|
||||||
var securityTokenReceivedNotification = await RunSecurityTokenReceivedNotificationAsync(message);
|
var securityTokenReceivedContext = await RunSecurityTokenReceivedEventAsync(message);
|
||||||
if (securityTokenReceivedNotification.HandledResponse)
|
if (securityTokenReceivedContext.HandledResponse)
|
||||||
{
|
{
|
||||||
return securityTokenReceivedNotification.AuthenticationTicket;
|
return securityTokenReceivedContext.AuthenticationTicket;
|
||||||
}
|
}
|
||||||
else if (securityTokenReceivedNotification.Skipped)
|
else if (securityTokenReceivedContext.Skipped)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -523,24 +523,24 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
|
|
||||||
await ValidateOpenIdConnectProtocolAsync(jwt, message);
|
await ValidateOpenIdConnectProtocolAsync(jwt, message);
|
||||||
|
|
||||||
var securityTokenValidatedNotification = await RunSecurityTokenValidatedNotificationAsync(message, ticket);
|
var securityTokenValidatedContext = await RunSecurityTokenValidatedEventAsync(message, ticket);
|
||||||
if (securityTokenValidatedNotification.HandledResponse)
|
if (securityTokenValidatedContext.HandledResponse)
|
||||||
{
|
{
|
||||||
return securityTokenValidatedNotification.AuthenticationTicket;
|
return securityTokenValidatedContext.AuthenticationTicket;
|
||||||
}
|
}
|
||||||
else if (securityTokenValidatedNotification.Skipped)
|
else if (securityTokenValidatedContext.Skipped)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.Code != null)
|
if (message.Code != null)
|
||||||
{
|
{
|
||||||
var authorizationCodeReceivedNotification = await RunAuthorizationCodeReceivedNotificationAsync(message, properties, ticket, jwt);
|
var authorizationCodeReceivedContext = await RunAuthorizationCodeReceivedEventAsync(message, properties, ticket, jwt);
|
||||||
if (authorizationCodeReceivedNotification.HandledResponse)
|
if (authorizationCodeReceivedContext.HandledResponse)
|
||||||
{
|
{
|
||||||
return authorizationCodeReceivedNotification.AuthenticationTicket;
|
return authorizationCodeReceivedContext.AuthenticationTicket;
|
||||||
}
|
}
|
||||||
else if (authorizationCodeReceivedNotification.Skipped)
|
else if (authorizationCodeReceivedContext.Skipped)
|
||||||
{
|
{
|
||||||
return null;
|
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());
|
Logger.LogDebug(Resources.OIDCH_0001_MessageReceived, message.BuildRedirectUrl());
|
||||||
var messageReceivedNotification =
|
var messageReceivedContext =
|
||||||
new MessageReceivedNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>(Context, Options)
|
new MessageReceivedContext<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>(Context, Options)
|
||||||
{
|
{
|
||||||
ProtocolMessage = message
|
ProtocolMessage = message
|
||||||
};
|
};
|
||||||
|
|
||||||
await Options.Notifications.MessageReceived(messageReceivedNotification);
|
await Options.Events.MessageReceived(messageReceivedContext);
|
||||||
if (messageReceivedNotification.HandledResponse)
|
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) ?
|
var redirectUri = properties.Items.ContainsKey(OpenIdConnectAuthenticationDefaults.RedirectUriForCodePropertiesKey) ?
|
||||||
properties.Items[OpenIdConnectAuthenticationDefaults.RedirectUriForCodePropertiesKey] : Options.RedirectUri;
|
properties.Items[OpenIdConnectAuthenticationDefaults.RedirectUriForCodePropertiesKey] : Options.RedirectUri;
|
||||||
|
|
||||||
Logger.LogDebug(Resources.OIDCH_0014_AuthorizationCodeReceived, message.Code);
|
Logger.LogDebug(Resources.OIDCH_0014_AuthorizationCodeReceived, message.Code);
|
||||||
|
|
||||||
var authorizationCodeReceivedNotification = new AuthorizationCodeReceivedNotification(Context, Options)
|
var authorizationCodeReceivedContext = new AuthorizationCodeReceivedContext(Context, Options)
|
||||||
{
|
{
|
||||||
Code = message.Code,
|
Code = message.Code,
|
||||||
ProtocolMessage = message,
|
ProtocolMessage = message,
|
||||||
|
|
@ -783,105 +783,105 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
JwtSecurityToken = jwt
|
JwtSecurityToken = jwt
|
||||||
};
|
};
|
||||||
|
|
||||||
await Options.Notifications.AuthorizationCodeReceived(authorizationCodeReceivedNotification);
|
await Options.Events.AuthorizationCodeReceived(authorizationCodeReceivedContext);
|
||||||
if (authorizationCodeReceivedNotification.HandledResponse)
|
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);
|
Logger.LogDebug(Resources.OIDCH_0042_AuthorizationCodeRedeemed, message.Code);
|
||||||
var authorizationCodeRedeemedNotification = new AuthorizationCodeRedeemedNotification(Context, Options)
|
var authorizationCodeRedeemedContext = new AuthorizationCodeRedeemedContext(Context, Options)
|
||||||
{
|
{
|
||||||
Code = message.Code,
|
Code = message.Code,
|
||||||
ProtocolMessage = message,
|
ProtocolMessage = message,
|
||||||
TokenEndpointResponse = tokenEndpointResponse
|
TokenEndpointResponse = tokenEndpointResponse
|
||||||
};
|
};
|
||||||
|
|
||||||
await Options.Notifications.AuthorizationCodeRedeemed(authorizationCodeRedeemedNotification);
|
await Options.Events.AuthorizationCodeRedeemed(authorizationCodeRedeemedContext);
|
||||||
if (authorizationCodeRedeemedNotification.HandledResponse)
|
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);
|
Logger.LogDebug(Resources.OIDCH_0020_IdTokenReceived, message.IdToken);
|
||||||
var securityTokenReceivedNotification =
|
var securityTokenReceivedContext =
|
||||||
new SecurityTokenReceivedNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>(Context, Options)
|
new SecurityTokenReceivedContext<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>(Context, Options)
|
||||||
{
|
{
|
||||||
ProtocolMessage = message,
|
ProtocolMessage = message,
|
||||||
};
|
};
|
||||||
|
|
||||||
await Options.Notifications.SecurityTokenReceived(securityTokenReceivedNotification);
|
await Options.Events.SecurityTokenReceived(securityTokenReceivedContext);
|
||||||
if (securityTokenReceivedNotification.HandledResponse)
|
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 =
|
var securityTokenValidatedContext =
|
||||||
new SecurityTokenValidatedNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>(Context, Options)
|
new SecurityTokenValidatedContext<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>(Context, Options)
|
||||||
{
|
{
|
||||||
AuthenticationTicket = ticket,
|
AuthenticationTicket = ticket,
|
||||||
ProtocolMessage = message
|
ProtocolMessage = message
|
||||||
};
|
};
|
||||||
|
|
||||||
await Options.Notifications.SecurityTokenValidated(securityTokenValidatedNotification);
|
await Options.Events.SecurityTokenValidated(securityTokenValidatedContext);
|
||||||
if (securityTokenValidatedNotification.HandledResponse)
|
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 =
|
var authenticationFailedContext =
|
||||||
new AuthenticationFailedNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>(Context, Options)
|
new AuthenticationFailedContext<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>(Context, Options)
|
||||||
{
|
{
|
||||||
ProtocolMessage = message,
|
ProtocolMessage = message,
|
||||||
Exception = exception
|
Exception = exception
|
||||||
};
|
};
|
||||||
|
|
||||||
await Options.Notifications.AuthenticationFailed(authenticationFailedNotification);
|
await Options.Events.AuthenticationFailed(authenticationFailedContext);
|
||||||
if (authenticationFailedNotification.HandledResponse)
|
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)
|
private AuthenticationTicket ValidateToken(string idToken, OpenIdConnectMessage message, AuthenticationProperties properties, TokenValidationParameters validationParameters, out JwtSecurityToken jwt)
|
||||||
|
|
|
||||||
|
|
@ -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))
|
if (string.IsNullOrEmpty(Options.TokenValidationParameters.ValidAudience) && !string.IsNullOrEmpty(Options.ClientId))
|
||||||
|
|
@ -162,7 +162,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
var webRequestHandler = handler as WebRequestHandler;
|
var webRequestHandler = handler as WebRequestHandler;
|
||||||
if (webRequestHandler == null)
|
if (webRequestHandler == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(Resources.OIDCH_0102_ExceptionValidatorHandlerMismatch);
|
throw new InvalidOperationException(Resources.OIDCH_0102_Exception_ValidatorHandlerMismatch);
|
||||||
}
|
}
|
||||||
webRequestHandler.ServerCertificateValidationCallback = options.BackchannelCertificateValidator.Validate;
|
webRequestHandler.ServerCertificateValidationCallback = options.BackchannelCertificateValidator.Validate;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -160,9 +160,9 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
public bool CacheNonces { get; set; }
|
public bool CacheNonces { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
public OpenIdConnectAuthenticationNotifications Notifications { get; set; } = new OpenIdConnectAuthenticationNotifications();
|
public OpenIdConnectAuthenticationEvents Events { get; set; } = new OpenIdConnectAuthenticationEvents();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the <see cref="OpenIdConnectProtocolValidator"/> that is used to ensure that the 'id_token' received
|
/// Gets or sets the <see cref="OpenIdConnectProtocolValidator"/> that is used to ensure that the 'id_token' received
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ namespace Microsoft.AspNet.Authentication.Twitter
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Specifies callback methods which the <see cref="TwitterAuthenticationMiddleware"></see> invokes to enable developer control over the authentication process. />
|
/// Specifies callback methods which the <see cref="TwitterAuthenticationMiddleware"></see> invokes to enable developer control over the authentication process. />
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface ITwitterAuthenticationNotifications
|
public interface ITwitterAuthenticationEvents
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Invoked whenever Twitter succesfully authenticates a user
|
/// Invoked whenever Twitter succesfully authenticates a user
|
||||||
|
|
@ -7,14 +7,14 @@ using System.Threading.Tasks;
|
||||||
namespace Microsoft.AspNet.Authentication.Twitter
|
namespace Microsoft.AspNet.Authentication.Twitter
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Default <see cref="ITwitterAuthenticationNotifications"/> implementation.
|
/// Default <see cref="ITwitterAuthenticationEvents"/> implementation.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class TwitterAuthenticationNotifications : ITwitterAuthenticationNotifications
|
public class TwitterAuthenticationEvents : ITwitterAuthenticationEvents
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a <see cref="TwitterAuthenticationNotifications"/>
|
/// Initializes a <see cref="TwitterAuthenticationEvents"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public TwitterAuthenticationNotifications()
|
public TwitterAuthenticationEvents()
|
||||||
{
|
{
|
||||||
OnAuthenticated = context => Task.FromResult<object>(null);
|
OnAuthenticated = context => Task.FromResult<object>(null);
|
||||||
OnReturnEndpoint = context => Task.FromResult<object>(null);
|
OnReturnEndpoint = context => Task.FromResult<object>(null);
|
||||||
|
|
@ -117,20 +117,20 @@ namespace Microsoft.AspNet.Authentication.Twitter
|
||||||
|
|
||||||
protected virtual async Task<AuthenticationTicket> CreateTicketAsync(ClaimsIdentity identity, AuthenticationProperties properties, AccessToken token)
|
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),
|
Principal = new ClaimsPrincipal(identity),
|
||||||
Properties = properties
|
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 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)
|
protected override async Task<bool> HandleUnauthorizedAsync([NotNull] ChallengeContext context)
|
||||||
|
|
@ -157,7 +157,7 @@ namespace Microsoft.AspNet.Authentication.Twitter
|
||||||
var redirectContext = new TwitterApplyRedirectContext(
|
var redirectContext = new TwitterApplyRedirectContext(
|
||||||
Context, Options,
|
Context, Options,
|
||||||
properties, twitterAuthenticationEndpoint);
|
properties, twitterAuthenticationEndpoint);
|
||||||
Options.Notifications.ApplyRedirect(redirectContext);
|
Options.Events.ApplyRedirect(redirectContext);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -184,7 +184,7 @@ namespace Microsoft.AspNet.Authentication.Twitter
|
||||||
};
|
};
|
||||||
model.Properties.RedirectUri = null;
|
model.Properties.RedirectUri = null;
|
||||||
|
|
||||||
await Options.Notifications.ReturnEndpoint(context);
|
await Options.Events.ReturnEndpoint(context);
|
||||||
|
|
||||||
if (context.SignInScheme != null && context.Principal != null)
|
if (context.SignInScheme != null && context.Principal != null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -51,9 +51,9 @@ namespace Microsoft.AspNet.Authentication.Twitter
|
||||||
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Exception_OptionMustBeProvided, nameof(Options.ConsumerKey)));
|
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)
|
if (Options.StateDataFormat == null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -102,9 +102,9 @@ namespace Microsoft.AspNet.Authentication.Twitter
|
||||||
public ISecureDataFormat<RequestToken> StateDataFormat { get; set; }
|
public ISecureDataFormat<RequestToken> StateDataFormat { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
public ITwitterAuthenticationNotifications Notifications { get; set; }
|
public ITwitterAuthenticationEvents Events { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines whether access tokens should be stored in the
|
/// Defines whether access tokens should be stored in the
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,9 @@ using Microsoft.AspNet.Http;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Authentication
|
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)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -5,22 +5,22 @@ using Microsoft.AspNet.Http;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Authentication
|
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
|
public bool HandledResponse
|
||||||
{
|
{
|
||||||
get { return State == NotificationResultState.HandledResponse; }
|
get { return State == EventResultState.HandledResponse; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Skipped
|
public bool Skipped
|
||||||
{
|
{
|
||||||
get { return State == NotificationResultState.Skipped; }
|
get { return State == EventResultState.Skipped; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -30,7 +30,7 @@ namespace Microsoft.AspNet.Authentication
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void HandleResponse()
|
public void HandleResponse()
|
||||||
{
|
{
|
||||||
State = NotificationResultState.HandledResponse;
|
State = EventResultState.HandledResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -39,11 +39,11 @@ namespace Microsoft.AspNet.Authentication
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void SkipToNextMiddleware()
|
public void SkipToNextMiddleware()
|
||||||
{
|
{
|
||||||
State = NotificationResultState.Skipped;
|
State = EventResultState.Skipped;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
public AuthenticationTicket AuthenticationTicket { get; set; }
|
public AuthenticationTicket AuthenticationTicket { get; set; }
|
||||||
}
|
}
|
||||||
|
|
@ -5,7 +5,7 @@ using System;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Authentication
|
namespace Microsoft.AspNet.Authentication
|
||||||
{
|
{
|
||||||
public enum NotificationResultState
|
public enum EventResultState
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Continue with normal processing.
|
/// Continue with normal processing.
|
||||||
|
|
@ -5,9 +5,9 @@ using Microsoft.AspNet.Http;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Authentication
|
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)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -5,9 +5,9 @@ using Microsoft.AspNet.Http;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Authentication
|
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)
|
: base(context, options)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
@ -9,13 +9,13 @@ namespace Microsoft.AspNet.Authentication
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// When a user configures the <see cref="AuthenticationMiddleware{TOptions}"/> to be notified prior to redirecting to an IdentityProvider
|
/// 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>
|
/// </summary>
|
||||||
/// <typeparam name="TMessage">protocol specific message.</typeparam>
|
/// <typeparam name="TMessage">protocol specific message.</typeparam>
|
||||||
/// <typeparam name="TOptions">protocol specific options.</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)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -5,9 +5,9 @@ using Microsoft.AspNet.Http;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Authentication
|
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)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -5,9 +5,9 @@ using Microsoft.AspNet.Http;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Authentication
|
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)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -341,7 +341,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
||||||
{
|
{
|
||||||
options.SystemClock = clock;
|
options.SystemClock = clock;
|
||||||
options.ExpireTimeSpan = TimeSpan.FromMinutes(10);
|
options.ExpireTimeSpan = TimeSpan.FromMinutes(10);
|
||||||
options.Notifications = new CookieAuthenticationNotifications
|
options.Events = new CookieAuthenticationEvents
|
||||||
{
|
{
|
||||||
OnValidatePrincipal = ctx =>
|
OnValidatePrincipal = ctx =>
|
||||||
{
|
{
|
||||||
|
|
@ -372,7 +372,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
||||||
options.SystemClock = clock;
|
options.SystemClock = clock;
|
||||||
options.ExpireTimeSpan = TimeSpan.FromMinutes(10);
|
options.ExpireTimeSpan = TimeSpan.FromMinutes(10);
|
||||||
options.SlidingExpiration = false;
|
options.SlidingExpiration = false;
|
||||||
options.Notifications = new CookieAuthenticationNotifications
|
options.Events = new CookieAuthenticationEvents
|
||||||
{
|
{
|
||||||
OnValidatePrincipal = ctx =>
|
OnValidatePrincipal = ctx =>
|
||||||
{
|
{
|
||||||
|
|
@ -402,7 +402,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
||||||
options.SystemClock = clock;
|
options.SystemClock = clock;
|
||||||
options.ExpireTimeSpan = TimeSpan.FromMinutes(10);
|
options.ExpireTimeSpan = TimeSpan.FromMinutes(10);
|
||||||
options.SlidingExpiration = false;
|
options.SlidingExpiration = false;
|
||||||
options.Notifications = new CookieAuthenticationNotifications
|
options.Events = new CookieAuthenticationEvents
|
||||||
{
|
{
|
||||||
OnValidatePrincipal = ctx =>
|
OnValidatePrincipal = ctx =>
|
||||||
{
|
{
|
||||||
|
|
@ -448,7 +448,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
||||||
{
|
{
|
||||||
options.SystemClock = clock;
|
options.SystemClock = clock;
|
||||||
options.ExpireTimeSpan = TimeSpan.FromMinutes(10);
|
options.ExpireTimeSpan = TimeSpan.FromMinutes(10);
|
||||||
options.Notifications = new CookieAuthenticationNotifications
|
options.Events = new CookieAuthenticationEvents
|
||||||
{
|
{
|
||||||
OnValidatePrincipal = ctx =>
|
OnValidatePrincipal = ctx =>
|
||||||
{
|
{
|
||||||
|
|
@ -495,7 +495,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
||||||
options.SystemClock = clock;
|
options.SystemClock = clock;
|
||||||
options.ExpireTimeSpan = TimeSpan.FromMinutes(10);
|
options.ExpireTimeSpan = TimeSpan.FromMinutes(10);
|
||||||
options.SlidingExpiration = false;
|
options.SlidingExpiration = false;
|
||||||
options.Notifications = new CookieAuthenticationNotifications()
|
options.Events = new CookieAuthenticationEvents()
|
||||||
{
|
{
|
||||||
OnResponseSignIn = context =>
|
OnResponseSignIn = context =>
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ namespace Microsoft.AspNet.Authentication.Facebook
|
||||||
{
|
{
|
||||||
options.AppId = "Test App Id";
|
options.AppId = "Test App Id";
|
||||||
options.AppSecret = "Test App Secret";
|
options.AppSecret = "Test App Secret";
|
||||||
options.Notifications = new OAuthAuthenticationNotifications
|
options.Events = new OAuthAuthenticationEvents
|
||||||
{
|
{
|
||||||
OnApplyRedirect = context =>
|
OnApplyRedirect = context =>
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -198,7 +198,7 @@ namespace Microsoft.AspNet.Authentication.Google
|
||||||
{
|
{
|
||||||
options.ClientId = "Test Id";
|
options.ClientId = "Test Id";
|
||||||
options.ClientSecret = "Test Secret";
|
options.ClientSecret = "Test Secret";
|
||||||
options.Notifications = new OAuthAuthenticationNotifications
|
options.Events = new OAuthAuthenticationEvents
|
||||||
{
|
{
|
||||||
OnApplyRedirect = context =>
|
OnApplyRedirect = context =>
|
||||||
{
|
{
|
||||||
|
|
@ -414,7 +414,7 @@ namespace Microsoft.AspNet.Authentication.Google
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
options.Notifications = new OAuthAuthenticationNotifications
|
options.Events = new OAuthAuthenticationEvents
|
||||||
{
|
{
|
||||||
OnAuthenticated = context =>
|
OnAuthenticated = context =>
|
||||||
{
|
{
|
||||||
|
|
@ -455,7 +455,7 @@ namespace Microsoft.AspNet.Authentication.Google
|
||||||
options.ClientSecret = "Test Secret";
|
options.ClientSecret = "Test Secret";
|
||||||
options.StateDataFormat = stateFormat;
|
options.StateDataFormat = stateFormat;
|
||||||
options.AccessType = "offline";
|
options.AccessType = "offline";
|
||||||
options.Notifications = new OAuthAuthenticationNotifications()
|
options.Events = new OAuthAuthenticationEvents()
|
||||||
{
|
{
|
||||||
OnAuthenticated = context =>
|
OnAuthenticated = context =>
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
{
|
{
|
||||||
options.AutomaticAuthentication = true;
|
options.AutomaticAuthentication = true;
|
||||||
|
|
||||||
options.Notifications.MessageReceived = notification =>
|
options.Events.MessageReceived = context =>
|
||||||
{
|
{
|
||||||
var claims = new[]
|
var claims = new[]
|
||||||
{
|
{
|
||||||
|
|
@ -76,11 +76,11 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
new Claim(ClaimsIdentity.DefaultNameClaimType, "bob")
|
new Claim(ClaimsIdentity.DefaultNameClaimType, "bob")
|
||||||
};
|
};
|
||||||
|
|
||||||
notification.AuthenticationTicket = new AuthenticationTicket(
|
context.AuthenticationTicket = new AuthenticationTicket(
|
||||||
new ClaimsPrincipal(new ClaimsIdentity(claims, notification.Options.AuthenticationScheme)),
|
new ClaimsPrincipal(new ClaimsIdentity(claims, context.Options.AuthenticationScheme)),
|
||||||
new AuthenticationProperties(), notification.Options.AuthenticationScheme);
|
new AuthenticationProperties(), context.Options.AuthenticationScheme);
|
||||||
|
|
||||||
notification.HandleResponse();
|
context.HandleResponse();
|
||||||
|
|
||||||
return Task.FromResult<object>(null);
|
return Task.FromResult<object>(null);
|
||||||
};
|
};
|
||||||
|
|
@ -114,7 +114,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
{
|
{
|
||||||
options.AutomaticAuthentication = true;
|
options.AutomaticAuthentication = true;
|
||||||
|
|
||||||
options.Notifications.SecurityTokenReceived = notification =>
|
options.Events.SecurityTokenReceived = context =>
|
||||||
{
|
{
|
||||||
var claims = new[]
|
var claims = new[]
|
||||||
{
|
{
|
||||||
|
|
@ -123,11 +123,11 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
new Claim(ClaimsIdentity.DefaultNameClaimType, "bob")
|
new Claim(ClaimsIdentity.DefaultNameClaimType, "bob")
|
||||||
};
|
};
|
||||||
|
|
||||||
notification.AuthenticationTicket = new AuthenticationTicket(
|
context.AuthenticationTicket = new AuthenticationTicket(
|
||||||
new ClaimsPrincipal(new ClaimsIdentity(claims, notification.Options.AuthenticationScheme)),
|
new ClaimsPrincipal(new ClaimsIdentity(claims, context.Options.AuthenticationScheme)),
|
||||||
new AuthenticationProperties(), notification.Options.AuthenticationScheme);
|
new AuthenticationProperties(), context.Options.AuthenticationScheme);
|
||||||
|
|
||||||
notification.HandleResponse();
|
context.HandleResponse();
|
||||||
|
|
||||||
return Task.FromResult<object>(null);
|
return Task.FromResult<object>(null);
|
||||||
};
|
};
|
||||||
|
|
@ -145,11 +145,11 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
{
|
{
|
||||||
options.AutomaticAuthentication = true;
|
options.AutomaticAuthentication = true;
|
||||||
|
|
||||||
options.Notifications.SecurityTokenValidated = notification =>
|
options.Events.SecurityTokenValidated = context =>
|
||||||
{
|
{
|
||||||
// Retrieve the NameIdentifier claim from the identity
|
// Retrieve the NameIdentifier claim from the identity
|
||||||
// returned by the custom security token validator.
|
// 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);
|
var identifier = identity.FindFirst(ClaimTypes.NameIdentifier);
|
||||||
|
|
||||||
identifier.Value.ShouldBe("Bob le Tout Puissant");
|
identifier.Value.ShouldBe("Bob le Tout Puissant");
|
||||||
|
|
@ -179,13 +179,13 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
{
|
{
|
||||||
options.AutomaticAuthentication = true;
|
options.AutomaticAuthentication = true;
|
||||||
|
|
||||||
options.Notifications.MessageReceived = notification =>
|
options.Events.MessageReceived = context =>
|
||||||
{
|
{
|
||||||
notification.Token = "CustomToken";
|
context.Token = "CustomToken";
|
||||||
return Task.FromResult<object>(null);
|
return Task.FromResult<object>(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
options.Notifications.SecurityTokenReceived = notification =>
|
options.Events.SecurityTokenReceived = context =>
|
||||||
{
|
{
|
||||||
var claims = new[]
|
var claims = new[]
|
||||||
{
|
{
|
||||||
|
|
@ -194,11 +194,11 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
new Claim(ClaimsIdentity.DefaultNameClaimType, "bob")
|
new Claim(ClaimsIdentity.DefaultNameClaimType, "bob")
|
||||||
};
|
};
|
||||||
|
|
||||||
notification.AuthenticationTicket = new AuthenticationTicket(
|
context.AuthenticationTicket = new AuthenticationTicket(
|
||||||
new ClaimsPrincipal(new ClaimsIdentity(claims, notification.Options.AuthenticationScheme)),
|
new ClaimsPrincipal(new ClaimsIdentity(claims, context.Options.AuthenticationScheme)),
|
||||||
new AuthenticationProperties(), notification.Options.AuthenticationScheme);
|
new AuthenticationProperties(), context.Options.AuthenticationScheme);
|
||||||
|
|
||||||
notification.HandleResponse();
|
context.HandleResponse();
|
||||||
|
|
||||||
return Task.FromResult<object>(null);
|
return Task.FromResult<object>(null);
|
||||||
};
|
};
|
||||||
|
|
@ -214,7 +214,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
{
|
{
|
||||||
var server = CreateServer(options =>
|
var server = CreateServer(options =>
|
||||||
{
|
{
|
||||||
options.Notifications.SecurityTokenReceived = notification =>
|
options.Events.SecurityTokenReceived = context =>
|
||||||
{
|
{
|
||||||
var claims = new[]
|
var claims = new[]
|
||||||
{
|
{
|
||||||
|
|
@ -223,11 +223,11 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
new Claim(ClaimsIdentity.DefaultNameClaimType, "bob")
|
new Claim(ClaimsIdentity.DefaultNameClaimType, "bob")
|
||||||
};
|
};
|
||||||
|
|
||||||
notification.AuthenticationTicket = new AuthenticationTicket(
|
context.AuthenticationTicket = new AuthenticationTicket(
|
||||||
new ClaimsPrincipal(new ClaimsIdentity(claims, notification.Options.AuthenticationScheme)),
|
new ClaimsPrincipal(new ClaimsIdentity(claims, context.Options.AuthenticationScheme)),
|
||||||
new AuthenticationProperties(), notification.Options.AuthenticationScheme);
|
new AuthenticationProperties(), context.Options.AuthenticationScheme);
|
||||||
|
|
||||||
notification.HandleResponse();
|
context.HandleResponse();
|
||||||
|
|
||||||
return Task.FromResult<object>(null);
|
return Task.FromResult<object>(null);
|
||||||
};
|
};
|
||||||
|
|
@ -242,7 +242,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
{
|
{
|
||||||
var server = CreateServer(options =>
|
var server = CreateServer(options =>
|
||||||
{
|
{
|
||||||
options.Notifications.SecurityTokenReceived = notification =>
|
options.Events.SecurityTokenReceived = context =>
|
||||||
{
|
{
|
||||||
var claims = new[]
|
var claims = new[]
|
||||||
{
|
{
|
||||||
|
|
@ -251,11 +251,11 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
new Claim(ClaimsIdentity.DefaultNameClaimType, "bob")
|
new Claim(ClaimsIdentity.DefaultNameClaimType, "bob")
|
||||||
};
|
};
|
||||||
|
|
||||||
notification.AuthenticationTicket = new AuthenticationTicket(
|
context.AuthenticationTicket = new AuthenticationTicket(
|
||||||
new ClaimsPrincipal(new ClaimsIdentity(claims, notification.Options.AuthenticationScheme)),
|
new ClaimsPrincipal(new ClaimsIdentity(claims, context.Options.AuthenticationScheme)),
|
||||||
new AuthenticationProperties(), notification.Options.AuthenticationScheme);
|
new AuthenticationProperties(), context.Options.AuthenticationScheme);
|
||||||
|
|
||||||
notification.HandleResponse();
|
context.HandleResponse();
|
||||||
|
|
||||||
return Task.FromResult<object>(null);
|
return Task.FromResult<object>(null);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ namespace Microsoft.AspNet.Authentication.Tests.MicrosoftAccount
|
||||||
{
|
{
|
||||||
options.ClientId = "Test Client Id";
|
options.ClientId = "Test Client Id";
|
||||||
options.ClientSecret = "Test Client Secret";
|
options.ClientSecret = "Test Client Secret";
|
||||||
options.Notifications = new OAuthAuthenticationNotifications
|
options.Events = new OAuthAuthenticationEvents
|
||||||
{
|
{
|
||||||
OnApplyRedirect = context =>
|
OnApplyRedirect = context =>
|
||||||
{
|
{
|
||||||
|
|
@ -143,7 +143,7 @@ namespace Microsoft.AspNet.Authentication.Tests.MicrosoftAccount
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
options.Notifications = new OAuthAuthenticationNotifications
|
options.Events = new OAuthAuthenticationEvents
|
||||||
{
|
{
|
||||||
OnAuthenticated = context =>
|
OnAuthenticated = context =>
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -94,26 +94,26 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup a notification to check for expected state.
|
// Setup an event to check for expected state.
|
||||||
// The state gets set by the runtime after the 'MessageReceivedNotification'
|
// The state gets set by the runtime after the 'MessageReceivedContext'
|
||||||
private static void SetStateOptions(OpenIdConnectAuthenticationOptions options)
|
private static void SetStateOptions(OpenIdConnectAuthenticationOptions options)
|
||||||
{
|
{
|
||||||
options.AuthenticationScheme = "OpenIdConnectHandlerTest";
|
options.AuthenticationScheme = "OpenIdConnectHandlerTest";
|
||||||
options.ConfigurationManager = TestUtilities.DefaultOpenIdConnectConfigurationManager;
|
options.ConfigurationManager = TestUtilities.DefaultOpenIdConnectConfigurationManager;
|
||||||
options.ClientId = Guid.NewGuid().ToString();
|
options.ClientId = Guid.NewGuid().ToString();
|
||||||
options.StateDataFormat = new AuthenticationPropertiesFormaterKeyValue();
|
options.StateDataFormat = new AuthenticationPropertiesFormaterKeyValue();
|
||||||
options.Notifications = new OpenIdConnectAuthenticationNotifications
|
options.Events = new OpenIdConnectAuthenticationEvents
|
||||||
{
|
{
|
||||||
AuthorizationCodeRedeemed = notification =>
|
AuthorizationCodeRedeemed = context =>
|
||||||
{
|
{
|
||||||
notification.HandleResponse();
|
context.HandleResponse();
|
||||||
if (notification.ProtocolMessage.State == null && !notification.ProtocolMessage.Parameters.ContainsKey(ExpectedStateParameter))
|
if (context.ProtocolMessage.State == null && !context.ProtocolMessage.Parameters.ContainsKey(ExpectedStateParameter))
|
||||||
return Task.FromResult<object>(null);
|
return Task.FromResult<object>(null);
|
||||||
|
|
||||||
if (notification.ProtocolMessage.State == null || !notification.ProtocolMessage.Parameters.ContainsKey(ExpectedStateParameter))
|
if (context.ProtocolMessage.State == null || !context.ProtocolMessage.Parameters.ContainsKey(ExpectedStateParameter))
|
||||||
Assert.True(false, "(notification.ProtocolMessage.State=!= null || !notification.ProtocolMessage.Parameters.ContainsKey(expectedState)");
|
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);
|
return Task.FromResult<object>(null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -274,12 +274,12 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
||||||
DefaultOptions(options);
|
DefaultOptions(options);
|
||||||
options.SecurityTokenValidator = MockSecurityTokenValidator();
|
options.SecurityTokenValidator = MockSecurityTokenValidator();
|
||||||
options.ProtocolValidator = MockProtocolValidator();
|
options.ProtocolValidator = MockProtocolValidator();
|
||||||
options.Notifications =
|
options.Events =
|
||||||
new OpenIdConnectAuthenticationNotifications
|
new OpenIdConnectAuthenticationEvents
|
||||||
{
|
{
|
||||||
AuthorizationCodeReceived = (notification) =>
|
AuthorizationCodeReceived = (context) =>
|
||||||
{
|
{
|
||||||
notification.HandleResponse();
|
context.HandleResponse();
|
||||||
return Task.FromResult<object>(null);
|
return Task.FromResult<object>(null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -290,12 +290,12 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
||||||
DefaultOptions(options);
|
DefaultOptions(options);
|
||||||
options.SecurityTokenValidator = MockSecurityTokenValidator();
|
options.SecurityTokenValidator = MockSecurityTokenValidator();
|
||||||
options.ProtocolValidator = MockProtocolValidator();
|
options.ProtocolValidator = MockProtocolValidator();
|
||||||
options.Notifications =
|
options.Events =
|
||||||
new OpenIdConnectAuthenticationNotifications
|
new OpenIdConnectAuthenticationEvents
|
||||||
{
|
{
|
||||||
AuthorizationCodeReceived = (notification) =>
|
AuthorizationCodeReceived = (context) =>
|
||||||
{
|
{
|
||||||
notification.SkipToNextMiddleware();
|
context.SkipToNextMiddleware();
|
||||||
return Task.FromResult<object>(null);
|
return Task.FromResult<object>(null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -306,12 +306,12 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
||||||
DefaultOptions(options);
|
DefaultOptions(options);
|
||||||
options.SecurityTokenValidator = MockSecurityTokenValidator();
|
options.SecurityTokenValidator = MockSecurityTokenValidator();
|
||||||
options.ProtocolValidator = MockProtocolValidator();
|
options.ProtocolValidator = MockProtocolValidator();
|
||||||
options.Notifications =
|
options.Events =
|
||||||
new OpenIdConnectAuthenticationNotifications
|
new OpenIdConnectAuthenticationEvents
|
||||||
{
|
{
|
||||||
AuthenticationFailed = (notification) =>
|
AuthenticationFailed = (context) =>
|
||||||
{
|
{
|
||||||
notification.HandleResponse();
|
context.HandleResponse();
|
||||||
return Task.FromResult<object>(null);
|
return Task.FromResult<object>(null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -322,12 +322,12 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
||||||
DefaultOptions(options);
|
DefaultOptions(options);
|
||||||
options.SecurityTokenValidator = MockSecurityTokenValidator();
|
options.SecurityTokenValidator = MockSecurityTokenValidator();
|
||||||
options.ProtocolValidator = MockProtocolValidator();
|
options.ProtocolValidator = MockProtocolValidator();
|
||||||
options.Notifications =
|
options.Events =
|
||||||
new OpenIdConnectAuthenticationNotifications
|
new OpenIdConnectAuthenticationEvents
|
||||||
{
|
{
|
||||||
AuthenticationFailed = (notification) =>
|
AuthenticationFailed = (context) =>
|
||||||
{
|
{
|
||||||
notification.SkipToNextMiddleware();
|
context.SkipToNextMiddleware();
|
||||||
return Task.FromResult<object>(null);
|
return Task.FromResult<object>(null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -336,12 +336,12 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
||||||
private static void MessageReceivedHandledOptions(OpenIdConnectAuthenticationOptions options)
|
private static void MessageReceivedHandledOptions(OpenIdConnectAuthenticationOptions options)
|
||||||
{
|
{
|
||||||
DefaultOptions(options);
|
DefaultOptions(options);
|
||||||
options.Notifications =
|
options.Events =
|
||||||
new OpenIdConnectAuthenticationNotifications
|
new OpenIdConnectAuthenticationEvents
|
||||||
{
|
{
|
||||||
MessageReceived = (notification) =>
|
MessageReceived = (context) =>
|
||||||
{
|
{
|
||||||
notification.HandleResponse();
|
context.HandleResponse();
|
||||||
return Task.FromResult<object>(null);
|
return Task.FromResult<object>(null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -352,12 +352,12 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
||||||
DefaultOptions(options);
|
DefaultOptions(options);
|
||||||
options.ResponseType = OpenIdConnectResponseTypes.Code;
|
options.ResponseType = OpenIdConnectResponseTypes.Code;
|
||||||
options.StateDataFormat = new AuthenticationPropertiesFormaterKeyValue();
|
options.StateDataFormat = new AuthenticationPropertiesFormaterKeyValue();
|
||||||
options.Notifications =
|
options.Events =
|
||||||
new OpenIdConnectAuthenticationNotifications
|
new OpenIdConnectAuthenticationEvents
|
||||||
{
|
{
|
||||||
AuthorizationCodeRedeemed = (notification) =>
|
AuthorizationCodeRedeemed = (context) =>
|
||||||
{
|
{
|
||||||
notification.HandleResponse();
|
context.HandleResponse();
|
||||||
return Task.FromResult<object>(null);
|
return Task.FromResult<object>(null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -368,12 +368,12 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
||||||
DefaultOptions(options);
|
DefaultOptions(options);
|
||||||
options.ResponseType = OpenIdConnectResponseTypes.Code;
|
options.ResponseType = OpenIdConnectResponseTypes.Code;
|
||||||
options.StateDataFormat = new AuthenticationPropertiesFormaterKeyValue();
|
options.StateDataFormat = new AuthenticationPropertiesFormaterKeyValue();
|
||||||
options.Notifications =
|
options.Events =
|
||||||
new OpenIdConnectAuthenticationNotifications
|
new OpenIdConnectAuthenticationEvents
|
||||||
{
|
{
|
||||||
AuthorizationCodeRedeemed = (notification) =>
|
AuthorizationCodeRedeemed = (context) =>
|
||||||
{
|
{
|
||||||
notification.SkipToNextMiddleware();
|
context.SkipToNextMiddleware();
|
||||||
return Task.FromResult<object>(null);
|
return Task.FromResult<object>(null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -387,14 +387,14 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
||||||
options.StateDataFormat = new AuthenticationPropertiesFormaterKeyValue();
|
options.StateDataFormat = new AuthenticationPropertiesFormaterKeyValue();
|
||||||
options.GetClaimsFromUserInfoEndpoint = true;
|
options.GetClaimsFromUserInfoEndpoint = true;
|
||||||
options.SecurityTokenValidator = MockSecurityTokenValidator();
|
options.SecurityTokenValidator = MockSecurityTokenValidator();
|
||||||
options.Notifications =
|
options.Events =
|
||||||
new OpenIdConnectAuthenticationNotifications
|
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");
|
Assert.Equal(claimValue.Value, "test value");
|
||||||
notification.HandleResponse();
|
context.HandleResponse();
|
||||||
return Task.FromResult<object>(null);
|
return Task.FromResult<object>(null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -402,12 +402,12 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
||||||
private static void MessageReceivedSkippedOptions(OpenIdConnectAuthenticationOptions options)
|
private static void MessageReceivedSkippedOptions(OpenIdConnectAuthenticationOptions options)
|
||||||
{
|
{
|
||||||
DefaultOptions(options);
|
DefaultOptions(options);
|
||||||
options.Notifications =
|
options.Events =
|
||||||
new OpenIdConnectAuthenticationNotifications
|
new OpenIdConnectAuthenticationEvents
|
||||||
{
|
{
|
||||||
MessageReceived = (notification) =>
|
MessageReceived = (context) =>
|
||||||
{
|
{
|
||||||
notification.SkipToNextMiddleware();
|
context.SkipToNextMiddleware();
|
||||||
return Task.FromResult<object>(null);
|
return Task.FromResult<object>(null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -421,12 +421,12 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
||||||
private static void SecurityTokenReceivedHandledOptions(OpenIdConnectAuthenticationOptions options)
|
private static void SecurityTokenReceivedHandledOptions(OpenIdConnectAuthenticationOptions options)
|
||||||
{
|
{
|
||||||
DefaultOptions(options);
|
DefaultOptions(options);
|
||||||
options.Notifications =
|
options.Events =
|
||||||
new OpenIdConnectAuthenticationNotifications
|
new OpenIdConnectAuthenticationEvents
|
||||||
{
|
{
|
||||||
SecurityTokenReceived = (notification) =>
|
SecurityTokenReceived = (context) =>
|
||||||
{
|
{
|
||||||
notification.HandleResponse();
|
context.HandleResponse();
|
||||||
return Task.FromResult<object>(null);
|
return Task.FromResult<object>(null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -435,12 +435,12 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
||||||
private static void SecurityTokenReceivedSkippedOptions(OpenIdConnectAuthenticationOptions options)
|
private static void SecurityTokenReceivedSkippedOptions(OpenIdConnectAuthenticationOptions options)
|
||||||
{
|
{
|
||||||
DefaultOptions(options);
|
DefaultOptions(options);
|
||||||
options.Notifications =
|
options.Events =
|
||||||
new OpenIdConnectAuthenticationNotifications
|
new OpenIdConnectAuthenticationEvents
|
||||||
{
|
{
|
||||||
SecurityTokenReceived = (notification) =>
|
SecurityTokenReceived = (context) =>
|
||||||
{
|
{
|
||||||
notification.SkipToNextMiddleware();
|
context.SkipToNextMiddleware();
|
||||||
return Task.FromResult<object>(null);
|
return Task.FromResult<object>(null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -492,12 +492,12 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
||||||
private static void SecurityTokenValidatedHandledOptions(OpenIdConnectAuthenticationOptions options)
|
private static void SecurityTokenValidatedHandledOptions(OpenIdConnectAuthenticationOptions options)
|
||||||
{
|
{
|
||||||
SecurityTokenValidatorValidatesAllTokens(options);
|
SecurityTokenValidatorValidatesAllTokens(options);
|
||||||
options.Notifications =
|
options.Events =
|
||||||
new OpenIdConnectAuthenticationNotifications
|
new OpenIdConnectAuthenticationEvents
|
||||||
{
|
{
|
||||||
SecurityTokenValidated = (notification) =>
|
SecurityTokenValidated = (context) =>
|
||||||
{
|
{
|
||||||
notification.HandleResponse();
|
context.HandleResponse();
|
||||||
return Task.FromResult<object>(null);
|
return Task.FromResult<object>(null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -506,12 +506,12 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
||||||
private static void SecurityTokenValidatedSkippedOptions(OpenIdConnectAuthenticationOptions options)
|
private static void SecurityTokenValidatedSkippedOptions(OpenIdConnectAuthenticationOptions options)
|
||||||
{
|
{
|
||||||
SecurityTokenValidatorValidatesAllTokens(options);
|
SecurityTokenValidatorValidatesAllTokens(options);
|
||||||
options.Notifications =
|
options.Events =
|
||||||
new OpenIdConnectAuthenticationNotifications
|
new OpenIdConnectAuthenticationEvents
|
||||||
{
|
{
|
||||||
SecurityTokenValidated = (notification) =>
|
SecurityTokenValidated = (context) =>
|
||||||
{
|
{
|
||||||
notification.SkipToNextMiddleware();
|
context.SkipToNextMiddleware();
|
||||||
return Task.FromResult<object>(null);
|
return Task.FromResult<object>(null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tests RedirectToIdentityProviderNotification replaces the OpenIdConnectMesssage correctly.
|
/// Tests RedirectToIdentityProviderContext replaces the OpenIdConnectMesssage correctly.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Task</returns>
|
/// <returns>Task</returns>
|
||||||
[Theory]
|
[Theory]
|
||||||
|
|
@ -130,12 +130,12 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
||||||
mockOpenIdConnectMessage.Setup(m => m.CreateAuthenticationRequestUrl()).Returns(ExpectedAuthorizeRequest);
|
mockOpenIdConnectMessage.Setup(m => m.CreateAuthenticationRequestUrl()).Returns(ExpectedAuthorizeRequest);
|
||||||
mockOpenIdConnectMessage.Setup(m => m.CreateLogoutRequestUrl()).Returns(ExpectedLogoutRequest);
|
mockOpenIdConnectMessage.Setup(m => m.CreateLogoutRequestUrl()).Returns(ExpectedLogoutRequest);
|
||||||
options.AutomaticAuthentication = true;
|
options.AutomaticAuthentication = true;
|
||||||
options.Notifications =
|
options.Events =
|
||||||
new OpenIdConnectAuthenticationNotifications
|
new OpenIdConnectAuthenticationEvents
|
||||||
{
|
{
|
||||||
RedirectToIdentityProvider = (notification) =>
|
RedirectToIdentityProvider = (context) =>
|
||||||
{
|
{
|
||||||
notification.ProtocolMessage = mockOpenIdConnectMessage.Object;
|
context.ProtocolMessage = mockOpenIdConnectMessage.Object;
|
||||||
return Task.FromResult<object>(null);
|
return Task.FromResult<object>(null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -143,8 +143,8 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tests for users who want to add 'state'. There are two ways to do it.
|
/// 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.
|
/// 1. Users set 'state' (OpenIdConnectMessage.State) in the event. The runtime appends to that state.
|
||||||
/// 2. Users add to the AuthenticationProperties (notification.AuthenticationProperties), values will be serialized.
|
/// 2. Users add to the AuthenticationProperties (context.AuthenticationProperties), values will be serialized.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userSetsState"></param>
|
/// <param name="userSetsState"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
|
|
@ -163,11 +163,11 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
||||||
{
|
{
|
||||||
SetOptions(options, DefaultParameters(new string[] { OpenIdConnectParameterNames.State }), queryValues, stateDataFormat);
|
SetOptions(options, DefaultParameters(new string[] { OpenIdConnectParameterNames.State }), queryValues, stateDataFormat);
|
||||||
options.AutomaticAuthentication = challenge.Equals(ChallengeWithOutContext);
|
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);
|
return Task.FromResult<object>(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -207,21 +207,21 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task ChallengeWillUseNotifications()
|
public async Task ChallengeWillUseEvents()
|
||||||
{
|
{
|
||||||
var queryValues = new ExpectedQueryValues(DefaultAuthority);
|
var queryValues = new ExpectedQueryValues(DefaultAuthority);
|
||||||
var queryValuesSetInNotification = new ExpectedQueryValues(DefaultAuthority);
|
var queryValuesSetInEvent = new ExpectedQueryValues(DefaultAuthority);
|
||||||
var server = CreateServer(options =>
|
var server = CreateServer(options =>
|
||||||
{
|
{
|
||||||
SetOptions(options, DefaultParameters(), queryValues);
|
SetOptions(options, DefaultParameters(), queryValues);
|
||||||
options.Notifications = new OpenIdConnectAuthenticationNotifications
|
options.Events = new OpenIdConnectAuthenticationEvents
|
||||||
{
|
{
|
||||||
RedirectToIdentityProvider = notification =>
|
RedirectToIdentityProvider = context =>
|
||||||
{
|
{
|
||||||
notification.ProtocolMessage.ClientId = queryValuesSetInNotification.ClientId;
|
context.ProtocolMessage.ClientId = queryValuesSetInEvent.ClientId;
|
||||||
notification.ProtocolMessage.RedirectUri = queryValuesSetInNotification.RedirectUri;
|
context.ProtocolMessage.RedirectUri = queryValuesSetInEvent.RedirectUri;
|
||||||
notification.ProtocolMessage.Resource = queryValuesSetInNotification.Resource;
|
context.ProtocolMessage.Resource = queryValuesSetInEvent.Resource;
|
||||||
notification.ProtocolMessage.Scope = queryValuesSetInNotification.Scope;
|
context.ProtocolMessage.Scope = queryValuesSetInEvent.Scope;
|
||||||
return Task.FromResult<object>(null);
|
return Task.FromResult<object>(null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -229,7 +229,7 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
||||||
|
|
||||||
var transaction = await SendAsync(server, DefaultHost + Challenge);
|
var transaction = await SendAsync(server, DefaultHost + Challenge);
|
||||||
transaction.Response.StatusCode.ShouldBe(HttpStatusCode.Redirect);
|
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)
|
private void SetOptions(OpenIdConnectAuthenticationOptions options, List<string> parameters, ExpectedQueryValues queryValues, ISecureDataFormat<AuthenticationProperties> secureDataFormat = null)
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ namespace Microsoft.AspNet.Authentication.Twitter
|
||||||
{
|
{
|
||||||
options.ConsumerKey = "Test Consumer Key";
|
options.ConsumerKey = "Test Consumer Key";
|
||||||
options.ConsumerSecret = "Test Consumer Secret";
|
options.ConsumerSecret = "Test Consumer Secret";
|
||||||
options.Notifications = new TwitterAuthenticationNotifications
|
options.Events = new TwitterAuthenticationEvents
|
||||||
{
|
{
|
||||||
OnApplyRedirect = context =>
|
OnApplyRedirect = context =>
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue