Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Commit 1c0768f

Browse files
committed
#372 Flow mutable event state.
#358 Add a UserInformationReceived event. #327 Add AuthenticationCompleted event. #340 Split the Redirect event for Authentication and SignOut. Rename OnAuthorizationCodeRedeemed to OnTokenResponseReceived. Move IdTokenReceived to AuthorizationResponseReceived. Rename IdTokenValidated to AuthenticationValidated.
1 parent 92d5e4c commit 1c0768f

17 files changed

+322
-612
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using Microsoft.AspNet.Http;
5+
6+
namespace Microsoft.AspNet.Authentication.OpenIdConnect
7+
{
8+
public class AuthenticationCompletedContext : BaseControlContext<OpenIdConnectOptions>
9+
{
10+
public AuthenticationCompletedContext(HttpContext context, OpenIdConnectOptions options)
11+
: base(context, options)
12+
{
13+
}
14+
}
15+
}

src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/SecurityTokenReceivedContext.cs renamed to src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/AuthenticationValidatedContext.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66

77
namespace Microsoft.AspNet.Authentication.OpenIdConnect
88
{
9-
public class SecurityTokenReceivedContext : BaseControlContext<OpenIdConnectOptions>
9+
public class AuthenticationValidatedContext : BaseControlContext<OpenIdConnectOptions>
1010
{
11-
public SecurityTokenReceivedContext(HttpContext context, OpenIdConnectOptions options)
11+
public AuthenticationValidatedContext(HttpContext context, OpenIdConnectOptions options)
1212
: base(context, options)
1313
{
1414
}
1515

16-
public string SecurityToken { get; set; }
17-
1816
public OpenIdConnectMessage ProtocolMessage { get; set; }
17+
18+
public OpenIdConnectTokenEndpointResponse TokenEndpointResponse { get; set; }
1919
}
2020
}

src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/SecurityTokenValidatedContext.cs renamed to src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/AuthorizationResponseReceivedContext.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using Microsoft.AspNet.Http;
5+
using Microsoft.AspNet.Http.Authentication;
56
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
67

78
namespace Microsoft.AspNet.Authentication.OpenIdConnect
89
{
9-
public class SecurityTokenValidatedContext : BaseControlContext<OpenIdConnectOptions>
10+
public class AuthorizationResponseReceivedContext : BaseControlContext<OpenIdConnectOptions>
1011
{
11-
public SecurityTokenValidatedContext(HttpContext context, OpenIdConnectOptions options)
12+
public AuthorizationResponseReceivedContext(HttpContext context, OpenIdConnectOptions options)
1213
: base(context, options)
1314
{
1415
}
1516

1617
public OpenIdConnectMessage ProtocolMessage { get; set; }
18+
19+
public AuthenticationProperties Properties { get; set; }
1720
}
1821
}

src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/IOpenIdConnectEvents.cs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,54 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
1010
/// </summary>
1111
public interface IOpenIdConnectEvents
1212
{
13+
/// <summary>
14+
/// Invoked when the authentication process completes.
15+
/// </summary>
16+
Task AuthenticationCompleted(AuthenticationCompletedContext context);
17+
1318
/// <summary>
1419
/// Invoked if exceptions are thrown during request processing. The exceptions will be re-thrown after this event unless suppressed.
1520
/// </summary>
1621
Task AuthenticationFailed(AuthenticationFailedContext context);
1722

23+
/// <summary>
24+
/// Invoked after the id token has passed validation and a ClaimsIdentity has been generated.
25+
/// </summary>
26+
Task AuthenticationValidated(AuthenticationValidatedContext context);
27+
1828
/// <summary>
1929
/// Invoked after security token validation if an authorization code is present in the protocol message.
2030
/// </summary>
2131
Task AuthorizationCodeReceived(AuthorizationCodeReceivedContext context);
2232

2333
/// <summary>
24-
/// Invoked after "authorization code" is redeemed for tokens at the token endpoint.
34+
/// Invoked when an authorization response is received.
2535
/// </summary>
26-
Task AuthorizationCodeRedeemed(AuthorizationCodeRedeemedContext context);
36+
Task AuthorizationResponseReceived(AuthorizationResponseReceivedContext context);
2737

2838
/// <summary>
2939
/// Invoked when a protocol message is first received.
3040
/// </summary>
3141
Task MessageReceived(MessageReceivedContext context);
3242

3343
/// <summary>
34-
/// Invoked to manipulate redirects to the identity provider for SignIn, SignOut, or Challenge.
44+
/// Invoked before redirecting to the identity provider to authenticate.
3545
/// </summary>
36-
Task RedirectToIdentityProvider(RedirectToIdentityProviderContext context);
46+
Task RedirectToAuthenticationEndpoint(RedirectContext context);
3747

3848
/// <summary>
39-
/// Invoked with the security token that has been extracted from the protocol message.
49+
/// Invoked before redirecting to the identity provider to sign out.
50+
/// </summary>
51+
Task RedirectToEndSessionEndpoint(RedirectContext context);
52+
53+
/// <summary>
54+
/// Invoked after "authorization code" is redeemed for tokens at the token endpoint.
4055
/// </summary>
41-
Task SecurityTokenReceived(SecurityTokenReceivedContext context);
56+
Task TokenResponseReceived(TokenResponseReceivedContext context);
4257

4358
/// <summary>
44-
/// Invoked after the security token has passed validation and a ClaimsIdentity has been generated.
59+
/// Invoked when user information is retrieved from the UserInfoEndpoint.
4560
/// </summary>
46-
Task SecurityTokenValidated(SecurityTokenValidatedContext context);
61+
Task UserInformationReceived(UserInformationReceivedContext context);
4762
}
4863
}

src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/OpenIdConnectEvents.cs

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,53 +11,74 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
1111
/// </summary>
1212
public class OpenIdConnectEvents : IOpenIdConnectEvents
1313
{
14+
/// <summary>
15+
/// Invoked when the authentication process completes.
16+
/// </summary>
17+
public Func<AuthenticationCompletedContext, Task> OnAuthenticationCompleted { get; set; } = context => Task.FromResult(0);
18+
1419
/// <summary>
1520
/// Invoked if exceptions are thrown during request processing. The exceptions will be re-thrown after this event unless suppressed.
1621
/// </summary>
1722
public Func<AuthenticationFailedContext, Task> OnAuthenticationFailed { get; set; } = context => Task.FromResult(0);
1823

24+
/// <summary>
25+
/// Invoked after the id token has passed validation and a ClaimsIdentity has been generated.
26+
/// </summary>
27+
public Func<AuthenticationValidatedContext, Task> OnAuthenticationValidated { get; set; } = context => Task.FromResult(0);
28+
1929
/// <summary>
2030
/// Invoked after security token validation if an authorization code is present in the protocol message.
2131
/// </summary>
2232
public Func<AuthorizationCodeReceivedContext, Task> OnAuthorizationCodeReceived { get; set; } = context => Task.FromResult(0);
2333

2434
/// <summary>
25-
/// Invoked after "authorization code" is redeemed for tokens at the token endpoint.
35+
/// Invoked when an authorization response is received.
2636
/// </summary>
27-
public Func<AuthorizationCodeRedeemedContext, Task> OnAuthorizationCodeRedeemed { get; set; } = context => Task.FromResult(0);
37+
public Func<AuthorizationResponseReceivedContext, Task> OnAuthorizationResponseReceived { get; set; } = context => Task.FromResult(0);
2838

2939
/// <summary>
3040
/// Invoked when a protocol message is first received.
3141
/// </summary>
3242
public Func<MessageReceivedContext, Task> OnMessageReceived { get; set; } = context => Task.FromResult(0);
3343

3444
/// <summary>
35-
/// Invoked to manipulate redirects to the identity provider for SignIn, SignOut, or Challenge.
45+
/// Invoked before redirecting to the identity provider to authenticate.
3646
/// </summary>
37-
public Func<RedirectToIdentityProviderContext, Task> OnRedirectToIdentityProvider { get; set; } = context => Task.FromResult(0);
47+
public Func<RedirectContext, Task> OnRedirectToAuthenticationEndpoint { get; set; } = context => Task.FromResult(0);
3848

3949
/// <summary>
40-
/// Invoked with the security token that has been extracted from the protocol message.
50+
/// Invoked before redirecting to the identity provider to sign out.
4151
/// </summary>
42-
public Func<SecurityTokenReceivedContext, Task> OnSecurityTokenReceived { get; set; } = context => Task.FromResult(0);
52+
public Func<RedirectContext, Task> OnRedirectToEndSessionEndpoint { get; set; } = context => Task.FromResult(0);
4353

4454
/// <summary>
45-
/// Invoked after the security token has passed validation and a ClaimsIdentity has been generated.
55+
/// Invoked after "authorization code" is redeemed for tokens at the token endpoint.
56+
/// </summary>
57+
public Func<TokenResponseReceivedContext, Task> OnTokenResponseReceived { get; set; } = context => Task.FromResult(0);
58+
59+
/// <summary>
60+
/// Invoked when user information is retrieved from the UserInfoEndpoint.
4661
/// </summary>
47-
public Func<SecurityTokenValidatedContext, Task> OnSecurityTokenValidated { get; set; } = context => Task.FromResult(0);
62+
public Func<UserInformationReceivedContext, Task> OnUserInformationReceived { get; set; } = context => Task.FromResult(0);
63+
64+
public virtual Task AuthenticationCompleted(AuthenticationCompletedContext context) => OnAuthenticationCompleted(context);
4865

4966
public virtual Task AuthenticationFailed(AuthenticationFailedContext context) => OnAuthenticationFailed(context);
5067

68+
public virtual Task AuthenticationValidated(AuthenticationValidatedContext context) => OnAuthenticationValidated(context);
69+
5170
public virtual Task AuthorizationCodeReceived(AuthorizationCodeReceivedContext context) => OnAuthorizationCodeReceived(context);
5271

53-
public virtual Task AuthorizationCodeRedeemed(AuthorizationCodeRedeemedContext context) => OnAuthorizationCodeRedeemed(context);
72+
public virtual Task AuthorizationResponseReceived(AuthorizationResponseReceivedContext context) => OnAuthorizationResponseReceived(context);
5473

5574
public virtual Task MessageReceived(MessageReceivedContext context) => OnMessageReceived(context);
5675

57-
public virtual Task RedirectToIdentityProvider(RedirectToIdentityProviderContext context) => OnRedirectToIdentityProvider(context);
76+
public virtual Task RedirectToAuthenticationEndpoint(RedirectContext context) => OnRedirectToAuthenticationEndpoint(context);
77+
78+
public virtual Task RedirectToEndSessionEndpoint(RedirectContext context) => OnRedirectToEndSessionEndpoint(context);
5879

59-
public virtual Task SecurityTokenReceived(SecurityTokenReceivedContext context) => OnSecurityTokenReceived(context);
80+
public virtual Task TokenResponseReceived(TokenResponseReceivedContext context) => OnTokenResponseReceived(context);
6081

61-
public virtual Task SecurityTokenValidated(SecurityTokenValidatedContext context) => OnSecurityTokenValidated(context);
82+
public virtual Task UserInformationReceived(UserInformationReceivedContext context) => OnUserInformationReceived(context);
6283
}
6384
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using Microsoft.AspNet.Http;
5+
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
6+
7+
namespace Microsoft.AspNet.Authentication.OpenIdConnect
8+
{
9+
/// <summary>
10+
/// When a user configures the <see cref="OpenIdConnectMiddleware"/> to be notified prior to redirecting to an IdentityProvider
11+
/// an instance of <see cref="RedirectContext"/> is passed to the 'RedirectToAuthenticationEndpoint' or 'RedirectToEndSessionEndpoint' events.
12+
/// </summary>
13+
public class RedirectContext : BaseControlContext<OpenIdConnectOptions>
14+
{
15+
public RedirectContext(HttpContext context, OpenIdConnectOptions options)
16+
: base(context, options)
17+
{
18+
}
19+
20+
/// <summary>
21+
/// Gets or sets the <see cref="OpenIdConnectMessage"/>.
22+
/// </summary>
23+
public OpenIdConnectMessage ProtocolMessage { get; set; }
24+
}
25+
}

src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/RedirectToIdentityProviderContext.cs

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/AuthorizationCodeRedeemedContext.cs renamed to src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/TokenResponseReceivedContext.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,16 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
66
/// <summary>
77
/// This Context can be used to be informed when an 'AuthorizationCode' is redeemed for tokens at the token endpoint.
88
/// </summary>
9-
public class AuthorizationCodeRedeemedContext : BaseControlContext<OpenIdConnectOptions>
9+
public class TokenResponseReceivedContext : BaseControlContext<OpenIdConnectOptions>
1010
{
1111
/// <summary>
12-
/// Creates a <see cref="AuthorizationCodeRedeemedContext"/>
12+
/// Creates a <see cref="TokenResponseReceivedContext"/>
1313
/// </summary>
14-
public AuthorizationCodeRedeemedContext(HttpContext context, OpenIdConnectOptions options)
14+
public TokenResponseReceivedContext(HttpContext context, OpenIdConnectOptions options)
1515
: base(context, options)
1616
{
1717
}
1818

19-
/// <summary>
20-
/// Gets or sets the 'code'.
21-
/// </summary>
22-
public string Code { get; set; }
23-
2419
/// <summary>
2520
/// Gets or sets the <see cref="OpenIdConnectTokenEndpointResponse"/> that contains the tokens and json response received after redeeming the code at the token endpoint.
2621
/// </summary>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using Microsoft.AspNet.Http;
5+
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
6+
using Newtonsoft.Json.Linq;
7+
8+
namespace Microsoft.AspNet.Authentication.OpenIdConnect
9+
{
10+
public class UserInformationReceivedContext : BaseControlContext<OpenIdConnectOptions>
11+
{
12+
public UserInformationReceivedContext(HttpContext context, OpenIdConnectOptions options)
13+
: base(context, options)
14+
{
15+
}
16+
17+
public OpenIdConnectMessage ProtocolMessage { get; set; }
18+
19+
public JObject User { get; set; }
20+
}
21+
}

0 commit comments

Comments
 (0)