Move Context objects to OIDC and JwtBearer, remove generics.
This commit is contained in:
parent
e4f78176f9
commit
2aba485263
|
|
@ -5,9 +5,10 @@ using Microsoft.AspNet.Http;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Authentication.JwtBearer
|
namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
{
|
{
|
||||||
public class AuthenticationChallengeContext<TOptions> : BaseControlContext<TOptions>
|
public class AuthenticationChallengeContext : BaseControlContext<JwtBearerAuthenticationOptions>
|
||||||
{
|
{
|
||||||
public AuthenticationChallengeContext(HttpContext context, TOptions options) : base(context, options)
|
public AuthenticationChallengeContext(HttpContext context, JwtBearerAuthenticationOptions options)
|
||||||
|
: base(context, options)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,16 +4,15 @@
|
||||||
using System;
|
using System;
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Authentication
|
namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
{
|
{
|
||||||
public class AuthenticationFailedContext<TMessage, TOptions> : BaseControlContext<TOptions>
|
public class AuthenticationFailedContext : BaseControlContext<JwtBearerAuthenticationOptions>
|
||||||
{
|
{
|
||||||
public AuthenticationFailedContext(HttpContext context, TOptions options) : base(context, options)
|
public AuthenticationFailedContext(HttpContext context, JwtBearerAuthenticationOptions options)
|
||||||
|
: base(context, options)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public Exception Exception { get; set; }
|
public Exception Exception { get; set; }
|
||||||
|
|
||||||
public TMessage ProtocolMessage { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -30,26 +30,26 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
/// <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<AuthenticationFailedContext<HttpContext, JwtBearerAuthenticationOptions>, Task> AuthenticationFailed { get; set; }
|
public Func<AuthenticationFailedContext, 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<MessageReceivedContext<HttpContext, JwtBearerAuthenticationOptions>, Task> MessageReceived { get; set; }
|
public Func<MessageReceivedContext, 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<SecurityTokenReceivedContext<HttpContext, JwtBearerAuthenticationOptions>, Task> SecurityTokenReceived { get; set; }
|
public Func<SecurityTokenReceivedContext, 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<SecurityTokenValidatedContext<HttpContext, JwtBearerAuthenticationOptions>, Task> SecurityTokenValidated { get; set; }
|
public Func<SecurityTokenValidatedContext, 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<AuthenticationChallengeContext<JwtBearerAuthenticationOptions>, Task> ApplyChallenge { get; set; }
|
public Func<AuthenticationChallengeContext, Task> ApplyChallenge { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,16 +3,15 @@
|
||||||
|
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Authentication
|
namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
{
|
{
|
||||||
public class MessageReceivedContext<TMessage, TOptions> : BaseControlContext<TOptions>
|
public class MessageReceivedContext : BaseControlContext<JwtBearerAuthenticationOptions>
|
||||||
{
|
{
|
||||||
public MessageReceivedContext(HttpContext context, TOptions options) : base(context, options)
|
public MessageReceivedContext(HttpContext context, JwtBearerAuthenticationOptions options)
|
||||||
|
: base(context, options)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public TMessage ProtocolMessage { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Bearer Token. This will give application an opportunity to retrieve token from an alternation location.
|
/// Bearer Token. This will give application an opportunity to retrieve token from an alternation location.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -3,16 +3,15 @@
|
||||||
|
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Authentication
|
namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
{
|
{
|
||||||
public class SecurityTokenReceivedContext<TMessage, TOptions> : BaseControlContext<TOptions>
|
public class SecurityTokenReceivedContext : BaseControlContext<JwtBearerAuthenticationOptions>
|
||||||
{
|
{
|
||||||
public SecurityTokenReceivedContext(HttpContext context, TOptions options) : base(context, options)
|
public SecurityTokenReceivedContext(HttpContext context, JwtBearerAuthenticationOptions options)
|
||||||
|
: base(context, options)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public string SecurityToken { get; set; }
|
public string SecurityToken { get; set; }
|
||||||
|
|
||||||
public TMessage ProtocolMessage { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3,14 +3,13 @@
|
||||||
|
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Authentication
|
namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
{
|
{
|
||||||
public class SecurityTokenValidatedContext<TMessage, TOptions> : BaseControlContext<TOptions>
|
public class SecurityTokenValidatedContext : BaseControlContext<JwtBearerAuthenticationOptions>
|
||||||
{
|
{
|
||||||
public SecurityTokenValidatedContext(HttpContext context, TOptions options) : base(context, options)
|
public SecurityTokenValidatedContext(HttpContext context, JwtBearerAuthenticationOptions options)
|
||||||
|
: base(context, options)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public TMessage ProtocolMessage { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -27,11 +27,7 @@ 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 messageReceivedContext =
|
var messageReceivedContext = new MessageReceivedContext(Context, Options);
|
||||||
new MessageReceivedContext<HttpContext, JwtBearerAuthenticationOptions>(Context, Options)
|
|
||||||
{
|
|
||||||
ProtocolMessage = Context,
|
|
||||||
};
|
|
||||||
|
|
||||||
// event can set the token
|
// event can set the token
|
||||||
await Options.Events.MessageReceived(messageReceivedContext);
|
await Options.Events.MessageReceived(messageReceivedContext);
|
||||||
|
|
@ -71,10 +67,8 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
}
|
}
|
||||||
|
|
||||||
// notify user token was received
|
// notify user token was received
|
||||||
var securityTokenReceivedContext =
|
var securityTokenReceivedContext = new SecurityTokenReceivedContext(Context, Options)
|
||||||
new SecurityTokenReceivedContext<HttpContext, JwtBearerAuthenticationOptions>(Context, Options)
|
|
||||||
{
|
{
|
||||||
ProtocolMessage = Context,
|
|
||||||
SecurityToken = token,
|
SecurityToken = token,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -117,9 +111,8 @@ 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 securityTokenValidatedContext = new SecurityTokenValidatedContext<HttpContext, JwtBearerAuthenticationOptions>(Context, Options)
|
var securityTokenValidatedContext = new SecurityTokenValidatedContext(Context, Options)
|
||||||
{
|
{
|
||||||
ProtocolMessage = Context,
|
|
||||||
AuthenticationTicket = ticket
|
AuthenticationTicket = ticket
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -150,12 +143,10 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
Options.ConfigurationManager.RequestRefresh();
|
Options.ConfigurationManager.RequestRefresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
var authenticationFailedContext =
|
var authenticationFailedContext = new AuthenticationFailedContext(Context, Options)
|
||||||
new AuthenticationFailedContext<HttpContext, JwtBearerAuthenticationOptions>(Context, Options)
|
{
|
||||||
{
|
Exception = ex
|
||||||
ProtocolMessage = Context,
|
};
|
||||||
Exception = ex
|
|
||||||
};
|
|
||||||
|
|
||||||
await Options.Events.AuthenticationFailed(authenticationFailedContext);
|
await Options.Events.AuthenticationFailed(authenticationFailedContext);
|
||||||
if (authenticationFailedContext.HandledResponse)
|
if (authenticationFailedContext.HandledResponse)
|
||||||
|
|
@ -175,7 +166,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.Events.ApplyChallenge(new AuthenticationChallengeContext<JwtBearerAuthenticationOptions>(Context, Options));
|
await Options.Events.ApplyChallenge(new AuthenticationChallengeContext(Context, Options));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// 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.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
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
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
// 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 Microsoft.AspNet.Http;
|
||||||
|
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
|
{
|
||||||
|
public class AuthenticationFailedContext : BaseControlContext<OpenIdConnectAuthenticationOptions>
|
||||||
|
{
|
||||||
|
public AuthenticationFailedContext(HttpContext context, OpenIdConnectAuthenticationOptions options)
|
||||||
|
: base(context, options)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public Exception Exception { get; set; }
|
||||||
|
|
||||||
|
public OpenIdConnectMessage ProtocolMessage { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// 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.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using Microsoft.AspNet.Http;
|
|
||||||
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.IdentityModel.Tokens.Jwt;
|
using System.IdentityModel.Tokens.Jwt;
|
||||||
|
using Microsoft.AspNet.Http;
|
||||||
|
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
{
|
{
|
||||||
|
|
@ -16,7 +16,8 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a <see cref="AuthorizationCodeReceivedContext"/>
|
/// Creates a <see cref="AuthorizationCodeReceivedContext"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public AuthorizationCodeReceivedContext(HttpContext context, OpenIdConnectAuthenticationOptions options) : base(context, options)
|
public AuthorizationCodeReceivedContext(HttpContext context, OpenIdConnectAuthenticationOptions options)
|
||||||
|
: base(context, options)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,8 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a <see cref="AuthorizationCodeRedeemedContext"/>
|
/// Creates a <see cref="AuthorizationCodeRedeemedContext"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public AuthorizationCodeRedeemedContext(HttpContext context, OpenIdConnectAuthenticationOptions options) : base(context, options)
|
public AuthorizationCodeRedeemedContext(HttpContext context, OpenIdConnectAuthenticationOptions options)
|
||||||
|
: base(context, options)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
// 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 Microsoft.AspNet.Http;
|
||||||
|
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
|
{
|
||||||
|
public class MessageReceivedContext : BaseControlContext<OpenIdConnectAuthenticationOptions>
|
||||||
|
{
|
||||||
|
public MessageReceivedContext(HttpContext context, OpenIdConnectAuthenticationOptions options)
|
||||||
|
: base(context, options)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public OpenIdConnectMessage ProtocolMessage { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Bearer Token. This will give application an opportunity to retrieve token from an alternation location.
|
||||||
|
/// </summary>
|
||||||
|
public string Token { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
{
|
{
|
||||||
|
|
@ -21,15 +20,15 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
AuthorizationCodeReceived = context => Task.FromResult(0);
|
AuthorizationCodeReceived = context => Task.FromResult(0);
|
||||||
AuthorizationCodeRedeemed = context => Task.FromResult(0);
|
AuthorizationCodeRedeemed = context => Task.FromResult(0);
|
||||||
MessageReceived = context => Task.FromResult(0);
|
MessageReceived = context => Task.FromResult(0);
|
||||||
|
RedirectToIdentityProvider = context => Task.FromResult(0);
|
||||||
SecurityTokenReceived = context => Task.FromResult(0);
|
SecurityTokenReceived = context => Task.FromResult(0);
|
||||||
SecurityTokenValidated = context => Task.FromResult(0);
|
SecurityTokenValidated = context => Task.FromResult(0);
|
||||||
RedirectToIdentityProvider = 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<AuthenticationFailedContext<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>, Task> AuthenticationFailed { get; set; }
|
public Func<AuthenticationFailedContext, Task> AuthenticationFailed { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Invoked after security token validation if an authorization code is present in the protocol message.
|
/// Invoked after security token validation if an authorization code is present in the protocol message.
|
||||||
|
|
@ -44,21 +43,21 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Invoked when a protocol message is first received.
|
/// Invoked when a protocol message is first received.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Func<MessageReceivedContext<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>, Task> MessageReceived { get; set; }
|
public Func<MessageReceivedContext, Task> MessageReceived { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Invoked to manipulate redirects to the identity provider for SignIn, SignOut, or Challenge.
|
/// Invoked to manipulate redirects to the identity provider for SignIn, SignOut, or Challenge.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Func<RedirectToIdentityProviderContext<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>, Task> RedirectToIdentityProvider { get; set; }
|
public Func<RedirectToIdentityProviderContext, Task> RedirectToIdentityProvider { 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<SecurityTokenReceivedContext<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>, Task> SecurityTokenReceived { get; set; }
|
public Func<SecurityTokenReceivedContext, 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<SecurityTokenValidatedContext<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>, Task> SecurityTokenValidated { get; set; }
|
public Func<SecurityTokenValidatedContext, Task> SecurityTokenValidated { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2,12 +2,13 @@
|
||||||
// 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 Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
|
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Authentication
|
namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
{
|
{
|
||||||
public class RedirectFromIdentityProviderContext<TMessage, TOptions> : BaseControlContext<TOptions>
|
public class RedirectFromIdentityProviderContext : BaseControlContext<OpenIdConnectAuthenticationOptions>
|
||||||
{
|
{
|
||||||
public RedirectFromIdentityProviderContext(HttpContext context, TOptions options)
|
public RedirectFromIdentityProviderContext(HttpContext context, OpenIdConnectAuthenticationOptions options)
|
||||||
: base(context, options)
|
: base(context, options)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
@ -16,6 +17,6 @@ namespace Microsoft.AspNet.Authentication
|
||||||
|
|
||||||
public bool IsRequestCompleted { get; set; }
|
public bool IsRequestCompleted { get; set; }
|
||||||
|
|
||||||
public TMessage ProtocolMessage { get; set; }
|
public OpenIdConnectMessage ProtocolMessage { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -4,25 +4,27 @@
|
||||||
using System;
|
using System;
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
using Microsoft.Framework.Internal;
|
using Microsoft.Framework.Internal;
|
||||||
|
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Authentication
|
namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
{
|
{
|
||||||
/// <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="RedirectFromIdentityProviderContext{TMessage, TOptions, TMessage}"/> is passed to the 'RedirectToIdentityProviderContext".
|
/// an instance of <see cref="RedirectFromIdentityProviderContext"/> 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 RedirectToIdentityProviderContext<TMessage, TOptions> : BaseControlContext<TOptions>
|
public class RedirectToIdentityProviderContext : BaseControlContext<OpenIdConnectAuthenticationOptions>
|
||||||
{
|
{
|
||||||
public RedirectToIdentityProviderContext([NotNull] HttpContext context, [NotNull] TOptions options) : base(context, options)
|
public RedirectToIdentityProviderContext([NotNull] HttpContext context, [NotNull] OpenIdConnectAuthenticationOptions options)
|
||||||
|
: base(context, options)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the <see cref="{TMessage}"/>.
|
/// Gets or sets the <see cref="OpenIdConnectMessage"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <exception cref="ArgumentNullException">if 'value' is null.</exception>
|
/// <exception cref="ArgumentNullException">if 'value' is null.</exception>
|
||||||
public TMessage ProtocolMessage { get; [param: NotNull] set; }
|
public OpenIdConnectMessage ProtocolMessage { get; [param: NotNull] set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
// 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 Microsoft.AspNet.Http;
|
||||||
|
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
|
{
|
||||||
|
public class SecurityTokenReceivedContext : BaseControlContext<OpenIdConnectAuthenticationOptions>
|
||||||
|
{
|
||||||
|
public SecurityTokenReceivedContext(HttpContext context, OpenIdConnectAuthenticationOptions options)
|
||||||
|
: base(context, options)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public string SecurityToken { get; set; }
|
||||||
|
|
||||||
|
public OpenIdConnectMessage ProtocolMessage { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
// 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 Microsoft.AspNet.Http;
|
||||||
|
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
|
{
|
||||||
|
public class SecurityTokenValidatedContext : BaseControlContext<OpenIdConnectAuthenticationOptions>
|
||||||
|
{
|
||||||
|
public SecurityTokenValidatedContext(HttpContext context, OpenIdConnectAuthenticationOptions options)
|
||||||
|
: base(context, options)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public OpenIdConnectMessage ProtocolMessage { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -89,7 +89,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
message.PostLogoutRedirectUri = Options.PostLogoutRedirectUri;
|
message.PostLogoutRedirectUri = Options.PostLogoutRedirectUri;
|
||||||
}
|
}
|
||||||
|
|
||||||
var redirectToIdentityProviderContext = new RedirectToIdentityProviderContext<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>(Context, Options)
|
var redirectToIdentityProviderContext = new RedirectToIdentityProviderContext(Context, Options)
|
||||||
{
|
{
|
||||||
ProtocolMessage = message
|
ProtocolMessage = message
|
||||||
};
|
};
|
||||||
|
|
@ -220,11 +220,10 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var redirectToIdentityProviderContext =
|
var redirectToIdentityProviderContext = new RedirectToIdentityProviderContext(Context, Options)
|
||||||
new RedirectToIdentityProviderContext<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>(Context, Options)
|
{
|
||||||
{
|
ProtocolMessage = message
|
||||||
ProtocolMessage = message
|
};
|
||||||
};
|
|
||||||
|
|
||||||
await Options.Events.RedirectToIdentityProvider(redirectToIdentityProviderContext);
|
await Options.Events.RedirectToIdentityProvider(redirectToIdentityProviderContext);
|
||||||
if (redirectToIdentityProviderContext.HandledResponse)
|
if (redirectToIdentityProviderContext.HandledResponse)
|
||||||
|
|
@ -745,14 +744,13 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<MessageReceivedContext<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>> RunMessageReceivedEventAsync(OpenIdConnectMessage message)
|
private async Task<MessageReceivedContext> RunMessageReceivedEventAsync(OpenIdConnectMessage message)
|
||||||
{
|
{
|
||||||
Logger.LogDebug(Resources.OIDCH_0001_MessageReceived, message.BuildRedirectUrl());
|
Logger.LogDebug(Resources.OIDCH_0001_MessageReceived, message.BuildRedirectUrl());
|
||||||
var messageReceivedContext =
|
var messageReceivedContext = new MessageReceivedContext(Context, Options)
|
||||||
new MessageReceivedContext<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>(Context, Options)
|
{
|
||||||
{
|
ProtocolMessage = message
|
||||||
ProtocolMessage = message
|
};
|
||||||
};
|
|
||||||
|
|
||||||
await Options.Events.MessageReceived(messageReceivedContext);
|
await Options.Events.MessageReceived(messageReceivedContext);
|
||||||
if (messageReceivedContext.HandledResponse)
|
if (messageReceivedContext.HandledResponse)
|
||||||
|
|
@ -818,14 +816,13 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
return authorizationCodeRedeemedContext;
|
return authorizationCodeRedeemedContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<SecurityTokenReceivedContext<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>> RunSecurityTokenReceivedEventAsync(OpenIdConnectMessage message)
|
private async Task<SecurityTokenReceivedContext> RunSecurityTokenReceivedEventAsync(OpenIdConnectMessage message)
|
||||||
{
|
{
|
||||||
Logger.LogDebug(Resources.OIDCH_0020_IdTokenReceived, message.IdToken);
|
Logger.LogDebug(Resources.OIDCH_0020_IdTokenReceived, message.IdToken);
|
||||||
var securityTokenReceivedContext =
|
var securityTokenReceivedContext = new SecurityTokenReceivedContext(Context, Options)
|
||||||
new SecurityTokenReceivedContext<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>(Context, Options)
|
{
|
||||||
{
|
ProtocolMessage = message,
|
||||||
ProtocolMessage = message,
|
};
|
||||||
};
|
|
||||||
|
|
||||||
await Options.Events.SecurityTokenReceived(securityTokenReceivedContext);
|
await Options.Events.SecurityTokenReceived(securityTokenReceivedContext);
|
||||||
if (securityTokenReceivedContext.HandledResponse)
|
if (securityTokenReceivedContext.HandledResponse)
|
||||||
|
|
@ -840,14 +837,13 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
return securityTokenReceivedContext;
|
return securityTokenReceivedContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<SecurityTokenValidatedContext<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>> RunSecurityTokenValidatedEventAsync(OpenIdConnectMessage message, AuthenticationTicket ticket)
|
private async Task<SecurityTokenValidatedContext> RunSecurityTokenValidatedEventAsync(OpenIdConnectMessage message, AuthenticationTicket ticket)
|
||||||
{
|
{
|
||||||
var securityTokenValidatedContext =
|
var securityTokenValidatedContext = new SecurityTokenValidatedContext(Context, Options)
|
||||||
new SecurityTokenValidatedContext<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>(Context, Options)
|
{
|
||||||
{
|
AuthenticationTicket = ticket,
|
||||||
AuthenticationTicket = ticket,
|
ProtocolMessage = message
|
||||||
ProtocolMessage = message
|
};
|
||||||
};
|
|
||||||
|
|
||||||
await Options.Events.SecurityTokenValidated(securityTokenValidatedContext);
|
await Options.Events.SecurityTokenValidated(securityTokenValidatedContext);
|
||||||
if (securityTokenValidatedContext.HandledResponse)
|
if (securityTokenValidatedContext.HandledResponse)
|
||||||
|
|
@ -862,14 +858,13 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
return securityTokenValidatedContext;
|
return securityTokenValidatedContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<AuthenticationFailedContext<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>> RunAuthenticationFailedEventAsync(OpenIdConnectMessage message, Exception exception)
|
private async Task<AuthenticationFailedContext> RunAuthenticationFailedEventAsync(OpenIdConnectMessage message, Exception exception)
|
||||||
{
|
{
|
||||||
var authenticationFailedContext =
|
var authenticationFailedContext = new AuthenticationFailedContext(Context, Options)
|
||||||
new AuthenticationFailedContext<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>(Context, Options)
|
{
|
||||||
{
|
ProtocolMessage = message,
|
||||||
ProtocolMessage = message,
|
Exception = exception
|
||||||
Exception = exception
|
};
|
||||||
};
|
|
||||||
|
|
||||||
await Options.Events.AuthenticationFailed(authenticationFailedContext);
|
await Options.Events.AuthenticationFailed(authenticationFailedContext);
|
||||||
if (authenticationFailedContext.HandledResponse)
|
if (authenticationFailedContext.HandledResponse)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue