Rename JwtBearer events
This commit is contained in:
parent
966fa6672f
commit
852f44a369
|
|
@ -21,21 +21,21 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
|||
/// <summary>
|
||||
/// Invoked when a protocol message is first received.
|
||||
/// </summary>
|
||||
Task MessageReceived(MessageReceivedContext context);
|
||||
Task ReceivingToken(ReceivingTokenContext context);
|
||||
|
||||
/// <summary>
|
||||
/// Invoked with the security token that has been extracted from the protocol message.
|
||||
/// </summary>
|
||||
Task SecurityTokenReceived(SecurityTokenReceivedContext context);
|
||||
Task ReceivedToken(ReceivedTokenContext context);
|
||||
|
||||
/// <summary>
|
||||
/// Invoked after the security token has passed validation and a ClaimsIdentity has been generated.
|
||||
/// </summary>
|
||||
Task SecurityTokenValidated(SecurityTokenValidatedContext context);
|
||||
Task ValidatedToken(ValidatedTokenContext context);
|
||||
|
||||
/// <summary>
|
||||
/// Invoked to apply a challenge sent back to the caller.
|
||||
/// </summary>
|
||||
Task ApplyChallenge(AuthenticationChallengeContext context);
|
||||
Task Challenge(JwtBearerChallengeContext context);
|
||||
}
|
||||
}
|
||||
|
|
@ -5,9 +5,9 @@ using Microsoft.AspNet.Http;
|
|||
|
||||
namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||
{
|
||||
public class SecurityTokenValidatedContext : BaseControlContext<JwtBearerOptions>
|
||||
public class JwtBearerChallengeContext : BaseControlContext<JwtBearerOptions>
|
||||
{
|
||||
public SecurityTokenValidatedContext(HttpContext context, JwtBearerOptions options)
|
||||
public JwtBearerChallengeContext(HttpContext context, JwtBearerOptions options)
|
||||
: base(context, options)
|
||||
{
|
||||
}
|
||||
|
|
@ -23,22 +23,22 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
|||
/// <summary>
|
||||
/// Invoked when a protocol message is first received.
|
||||
/// </summary>
|
||||
public Func<MessageReceivedContext, Task> OnMessageReceived { get; set; } = context => Task.FromResult(0);
|
||||
public Func<ReceivingTokenContext, Task> OnReceivingToken { get; set; } = context => Task.FromResult(0);
|
||||
|
||||
/// <summary>
|
||||
/// Invoked with the security token that has been extracted from the protocol message.
|
||||
/// </summary>
|
||||
public Func<SecurityTokenReceivedContext, Task> OnSecurityTokenReceived { get; set; } = context => Task.FromResult(0);
|
||||
public Func<ReceivedTokenContext, Task> OnReceivedToken { get; set; } = context => Task.FromResult(0);
|
||||
|
||||
/// <summary>
|
||||
/// Invoked after the security token has passed validation and a ClaimsIdentity has been generated.
|
||||
/// </summary>
|
||||
public Func<SecurityTokenValidatedContext, Task> OnSecurityTokenValidated { get; set; } = context => Task.FromResult(0);
|
||||
public Func<ValidatedTokenContext, Task> OnValidatedToken { get; set; } = context => Task.FromResult(0);
|
||||
|
||||
/// <summary>
|
||||
/// Invoked to apply a challenge sent back to the caller.
|
||||
/// </summary>
|
||||
public Func<AuthenticationChallengeContext, Task> OnApplyChallenge { get; set; } = context =>
|
||||
public Func<JwtBearerChallengeContext, Task> OnChallenge { get; set; } = context =>
|
||||
{
|
||||
context.HttpContext.Response.Headers.Append("WWW-Authenticate", context.Options.Challenge);
|
||||
return Task.FromResult(0);
|
||||
|
|
@ -46,12 +46,12 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
|||
|
||||
public virtual Task AuthenticationFailed(AuthenticationFailedContext context) => OnAuthenticationFailed(context);
|
||||
|
||||
public virtual Task MessageReceived(MessageReceivedContext context) => OnMessageReceived(context);
|
||||
public virtual Task ReceivingToken(ReceivingTokenContext context) => OnReceivingToken(context);
|
||||
|
||||
public virtual Task SecurityTokenReceived(SecurityTokenReceivedContext context) => OnSecurityTokenReceived(context);
|
||||
public virtual Task ReceivedToken(ReceivedTokenContext context) => OnReceivedToken(context);
|
||||
|
||||
public virtual Task SecurityTokenValidated(SecurityTokenValidatedContext context) => OnSecurityTokenValidated(context);
|
||||
public virtual Task ValidatedToken(ValidatedTokenContext context) => OnValidatedToken(context);
|
||||
|
||||
public virtual Task ApplyChallenge(AuthenticationChallengeContext context) => OnApplyChallenge(context);
|
||||
public virtual Task Challenge(JwtBearerChallengeContext context) => OnChallenge(context);
|
||||
}
|
||||
}
|
||||
|
|
@ -5,13 +5,13 @@ using Microsoft.AspNet.Http;
|
|||
|
||||
namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||
{
|
||||
public class SecurityTokenReceivedContext : BaseControlContext<JwtBearerOptions>
|
||||
public class ReceivedTokenContext : BaseControlContext<JwtBearerOptions>
|
||||
{
|
||||
public SecurityTokenReceivedContext(HttpContext context, JwtBearerOptions options)
|
||||
public ReceivedTokenContext(HttpContext context, JwtBearerOptions options)
|
||||
: base(context, options)
|
||||
{
|
||||
}
|
||||
|
||||
public string SecurityToken { get; set; }
|
||||
public string Token { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -5,9 +5,9 @@ using Microsoft.AspNet.Http;
|
|||
|
||||
namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||
{
|
||||
public class MessageReceivedContext : BaseControlContext<JwtBearerOptions>
|
||||
public class ReceivingTokenContext : BaseControlContext<JwtBearerOptions>
|
||||
{
|
||||
public MessageReceivedContext(HttpContext context, JwtBearerOptions options)
|
||||
public ReceivingTokenContext(HttpContext context, JwtBearerOptions options)
|
||||
: base(context, options)
|
||||
{
|
||||
}
|
||||
|
|
@ -5,9 +5,9 @@ using Microsoft.AspNet.Http;
|
|||
|
||||
namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||
{
|
||||
public class AuthenticationChallengeContext : BaseControlContext<JwtBearerOptions>
|
||||
public class ValidatedTokenContext : BaseControlContext<JwtBearerOptions>
|
||||
{
|
||||
public AuthenticationChallengeContext(HttpContext context, JwtBearerOptions options)
|
||||
public ValidatedTokenContext(HttpContext context, JwtBearerOptions options)
|
||||
: base(context, options)
|
||||
{
|
||||
}
|
||||
|
|
@ -26,22 +26,22 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
|||
try
|
||||
{
|
||||
// Give application opportunity to find from a different location, adjust, or reject token
|
||||
var messageReceivedContext = new MessageReceivedContext(Context, Options);
|
||||
var receivingTokenContext = new ReceivingTokenContext(Context, Options);
|
||||
|
||||
// event can set the token
|
||||
await Options.Events.MessageReceived(messageReceivedContext);
|
||||
if (messageReceivedContext.HandledResponse)
|
||||
await Options.Events.ReceivingToken(receivingTokenContext);
|
||||
if (receivingTokenContext.HandledResponse)
|
||||
{
|
||||
return messageReceivedContext.AuthenticationTicket;
|
||||
return receivingTokenContext.AuthenticationTicket;
|
||||
}
|
||||
|
||||
if (messageReceivedContext.Skipped)
|
||||
if (receivingTokenContext.Skipped)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// If application retrieved token from somewhere else, use that.
|
||||
token = messageReceivedContext.Token;
|
||||
token = receivingTokenContext.Token;
|
||||
|
||||
if (string.IsNullOrEmpty(token))
|
||||
{
|
||||
|
|
@ -66,18 +66,18 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
|||
}
|
||||
|
||||
// notify user token was received
|
||||
var securityTokenReceivedContext = new SecurityTokenReceivedContext(Context, Options)
|
||||
var receivedTokenContext = new ReceivedTokenContext(Context, Options)
|
||||
{
|
||||
SecurityToken = token,
|
||||
Token = token,
|
||||
};
|
||||
|
||||
await Options.Events.SecurityTokenReceived(securityTokenReceivedContext);
|
||||
if (securityTokenReceivedContext.HandledResponse)
|
||||
await Options.Events.ReceivedToken(receivedTokenContext);
|
||||
if (receivedTokenContext.HandledResponse)
|
||||
{
|
||||
return securityTokenReceivedContext.AuthenticationTicket;
|
||||
return receivedTokenContext.AuthenticationTicket;
|
||||
}
|
||||
|
||||
if (securityTokenReceivedContext.Skipped)
|
||||
if (receivedTokenContext.Skipped)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
|
@ -110,18 +110,18 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
|||
{
|
||||
var principal = validator.ValidateToken(token, validationParameters, out validatedToken);
|
||||
var ticket = new AuthenticationTicket(principal, new AuthenticationProperties(), Options.AuthenticationScheme);
|
||||
var securityTokenValidatedContext = new SecurityTokenValidatedContext(Context, Options)
|
||||
var validatedTokenContext = new ValidatedTokenContext(Context, Options)
|
||||
{
|
||||
AuthenticationTicket = ticket
|
||||
};
|
||||
|
||||
await Options.Events.SecurityTokenValidated(securityTokenValidatedContext);
|
||||
if (securityTokenValidatedContext.HandledResponse)
|
||||
await Options.Events.ValidatedToken(validatedTokenContext);
|
||||
if (validatedTokenContext.HandledResponse)
|
||||
{
|
||||
return securityTokenValidatedContext.AuthenticationTicket;
|
||||
return validatedTokenContext.AuthenticationTicket;
|
||||
}
|
||||
|
||||
if (securityTokenValidatedContext.Skipped)
|
||||
if (validatedTokenContext.Skipped)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
|
@ -165,7 +165,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
|||
protected override async Task<bool> HandleUnauthorizedAsync(ChallengeContext context)
|
||||
{
|
||||
Response.StatusCode = 401;
|
||||
await Options.Events.ApplyChallenge(new AuthenticationChallengeContext(Context, Options));
|
||||
await Options.Events.Challenge(new JwtBearerChallengeContext(Context, Options));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
|||
|
||||
options.Events = new JwtBearerEvents()
|
||||
{
|
||||
OnMessageReceived = context =>
|
||||
OnReceivingToken = context =>
|
||||
{
|
||||
var claims = new[]
|
||||
{
|
||||
|
|
@ -118,7 +118,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
|||
|
||||
options.Events = new JwtBearerEvents()
|
||||
{
|
||||
OnSecurityTokenReceived = context =>
|
||||
OnReceivedToken = context =>
|
||||
{
|
||||
var claims = new[]
|
||||
{
|
||||
|
|
@ -152,7 +152,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
|||
|
||||
options.Events = new JwtBearerEvents()
|
||||
{
|
||||
OnSecurityTokenValidated = context =>
|
||||
OnValidatedToken = context =>
|
||||
{
|
||||
// Retrieve the NameIdentifier claim from the identity
|
||||
// returned by the custom security token validator.
|
||||
|
|
@ -189,12 +189,12 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
|||
|
||||
options.Events = new JwtBearerEvents()
|
||||
{
|
||||
OnMessageReceived = context =>
|
||||
OnReceivingToken = context =>
|
||||
{
|
||||
context.Token = "CustomToken";
|
||||
return Task.FromResult<object>(null);
|
||||
},
|
||||
OnSecurityTokenReceived = context =>
|
||||
OnReceivedToken = context =>
|
||||
{
|
||||
var claims = new[]
|
||||
{
|
||||
|
|
@ -226,7 +226,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
|||
{
|
||||
options.Events = new JwtBearerEvents()
|
||||
{
|
||||
OnSecurityTokenReceived = context =>
|
||||
OnReceivedToken = context =>
|
||||
{
|
||||
var claims = new[]
|
||||
{
|
||||
|
|
@ -257,7 +257,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
|||
{
|
||||
options.Events = new JwtBearerEvents()
|
||||
{
|
||||
OnSecurityTokenReceived = context =>
|
||||
OnReceivedToken = context =>
|
||||
{
|
||||
var claims = new[]
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue