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

Commit 181b7af

Browse files
Finished work on the middleware events.
Renamed the AccessTokenReceived event to ParseAccessToken (+10 squashed commit) Squashed commit: [c6cdb40] Ensured the System using directives are listed before the others [daeb53c] Added NotNull attributes to all of the required constructor parameters of the events. [b7038ac] Aligned Owin.Security.OAuth.Validation with AspNet.Security.OAuth.Validation [b52f8f5] Added licensing to all the re-worked events so far and more whitespace work; Aligned Owin.Security.OAuth.Introspection to do the same thing as AspNet.Security.OAuth.Introspection; Fixed and added Introspection tests. [d35e849] Forgot to rename the delegate for token validation in the AspNet...Introspection middleware, fixed the tests and aligned test tokens to be the same values. [29c2428] Refactored the events of AspNet.Security.OAuth.Validation to be in-line with the changes to AspNet.Security.OAuth.Introspection. [0d18f2e] Rename the token validation event, whitespace an comment formatting. [2025b86] Fixed the logic that was blowing up all of the unit tests for AspNet.Security.OAuth.Introspection (+2 squashed commit) Squashed commit: [ea3cf84] Unsure why dotnet test crashes corehost.exe [cd63d7d] Removed BaseControlContext from events and customized the events and streamlined the process for AspNet.Security.OAuth.Introspection... But tests crash corehost.exe with a Stack Overflow for some odd reason (possible bug in corehost or with my environment). [87b3dc5] Removed the AuthenticationFailedContext events and the related try/catch blocks in all of the middleware. [7a7fbab] Finished initial work on Events for the middlewares. Squashed commit: [3ff2c22] WHY WON'T MY TESTS WORK AGH [3d7d436] Finished events - Build error fixes and exclusion of .build folder from tracked files. Squashed commits: [6e9a9fe] Finished work on Introspection and Validation events except for tests on a couple of the Introspection events. Also fixed the RootNamespaces of all of the projects. (+3 squashed commit) Squashed commit: [c572f5b] Whitespace changes mostly [c1ea6bc] Wrote some tests but missing AuthenticationFailedContext tests and tests for exceptions thrown. [f8ae71c] Finished events for the Validation middleware. Tests need to be created. (+1 squashed commits) Squashed commits: [36b8003] Finished events for the Validation middleware. Tests need to be created. (+8 squashed commit) Squashed commit: [b7038ac] Aligned Owin.Security.OAuth.Validation with AspNet.Security.OAuth.Validation [b52f8f5] Added licensing to all the re-worked events so far and more whitespace work; Aligned Owin.Security.OAuth.Introspection to do the same thing as AspNet.Security.OAuth.Introspection; Fixed and added Introspection tests. [d35e849] Forgot to rename the delegate for token validation in the AspNet...Introspection middleware, fixed the tests and aligned test tokens to be the same values. [29c2428] Refactored the events of AspNet.Security.OAuth.Validation to be in-line with the changes to AspNet.Security.OAuth.Introspection. [0d18f2e] Rename the token validation event, whitespace an comment formatting. [2025b86] Fixed the logic that was blowing up all of the unit tests for AspNet.Security.OAuth.Introspection (+2 squashed commit) Squashed commit: [ea3cf84] Unsure why dotnet test crashes corehost.exe [cd63d7d] Removed BaseControlContext from events and customized the events and streamlined the process for AspNet.Security.OAuth.Introspection... But tests crash corehost.exe with a Stack Overflow for some odd reason (possible bug in corehost or with my environment). [87b3dc5] Removed the AuthenticationFailedContext events and the related try/catch blocks in all of the middleware. [7a7fbab] Finished initial work on Events for the middlewares. Squashed commit: [3ff2c22] WHY WON'T MY TESTS WORK AGH [3d7d436] Finished events - Build error fixes and exclusion of .build folder from tracked files. Squashed commits: [6e9a9fe] Finished work on Introspection and Validation events except for tests on a couple of the Introspection events. Also fixed the RootNamespaces of all of the projects. (+3 squashed commit) Squashed commit: [c572f5b] Whitespace changes mostly [c1ea6bc] Wrote some tests but missing AuthenticationFailedContext tests and tests for exceptions thrown. [f8ae71c] Finished events for the Validation middleware. Tests need to be created. (+1 squashed commits) Squashed commits: [36b8003] Finished events for the Validation middleware. Tests need to be created. (+6 squashed commit) Squashed commit: [d35e849] Forgot to rename the delegate for token validation in the AspNet...Introspection middleware, fixed the tests and aligned test tokens to be the same values. [29c2428] Refactored the events of AspNet.Security.OAuth.Validation to be in-line with the changes to AspNet.Security.OAuth.Introspection. [0d18f2e] Rename the token validation event, whitespace an comment formatting. [2025b86] Fixed the logic that was blowing up all of the unit tests for AspNet.Security.OAuth.Introspection (+2 squashed commit) Squashed commit: [ea3cf84] Unsure why dotnet test crashes corehost.exe [cd63d7d] Removed BaseControlContext from events and customized the events and streamlined the process for AspNet.Security.OAuth.Introspection... But tests crash corehost.exe with a Stack Overflow for some odd reason (possible bug in corehost or with my environment). [87b3dc5] Removed the AuthenticationFailedContext events and the related try/catch blocks in all of the middleware. [7a7fbab] Finished initial work on Events for the middlewares. Squashed commit: [3ff2c22] WHY WON'T MY TESTS WORK AGH [3d7d436] Finished events - Build error fixes and exclusion of .build folder from tracked files. Squashed commits: [6e9a9fe] Finished work on Introspection and Validation events except for tests on a couple of the Introspection events. Also fixed the RootNamespaces of all of the projects. (+3 squashed commit) Squashed commit: [c572f5b] Whitespace changes mostly [c1ea6bc] Wrote some tests but missing AuthenticationFailedContext tests and tests for exceptions thrown. [f8ae71c] Finished events for the Validation middleware. Tests need to be created. (+1 squashed commits) Squashed commits: [36b8003] Finished events for the Validation middleware. Tests need to be created. (+2 squashed commit) Squashed commit: [0d18f2e] Rename the token validation event, whitespace an comment formatting. [2025b86] Fixed the logic that was blowing up all of the unit tests for AspNet.Security.OAuth.Introspection (+2 squashed commit) Squashed commit: [ea3cf84] Unsure why dotnet test crashes corehost.exe [cd63d7d] Removed BaseControlContext from events and customized the events and streamlined the process for AspNet.Security.OAuth.Introspection... But tests crash corehost.exe with a Stack Overflow for some odd reason (possible bug in corehost or with my environment). (+1 squashed commits) Squashed commits: [87b3dc5] Removed the AuthenticationFailedContext events and the related try/catch blocks in all of the middleware.
1 parent 7a7fbab commit 181b7af

File tree

52 files changed

+1288
-1690
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1288
-1690
lines changed

src/AspNet.Security.OAuth.Introspection/Events/AccessTokenReceivedContext.cs

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

src/AspNet.Security.OAuth.Introspection/Events/AuthenticationFailedContext.cs

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,33 @@
1-
using Microsoft.AspNetCore.Authentication;
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
3+
* See https://github.com/aspnet-contrib/AspNet.Security.OAuth.Extensions for more information
4+
* concerning the license and the contributors participating to this project.
5+
*/
6+
7+
using JetBrains.Annotations;
8+
using Microsoft.AspNetCore.Authentication;
29
using Microsoft.AspNetCore.Http;
310

4-
namespace AspNet.Security.OAuth.Introspection
5-
{
6-
public abstract class BaseIntrospectionContext : BaseControlContext
7-
{
11+
namespace AspNet.Security.OAuth.Introspection {
12+
/// <summary>
13+
/// Base class for all introspection events that holds common properties.
14+
/// </summary>
15+
public abstract class BaseIntrospectionContext : BaseContext {
816
public BaseIntrospectionContext(
9-
HttpContext context,
10-
OAuthIntrospectionOptions options)
17+
[NotNull]HttpContext context,
18+
[NotNull]OAuthIntrospectionOptions options)
1119
: base(context) {
1220
Options = options;
1321
}
1422

23+
/// <summary>
24+
/// Indicates the application has handled the event process.
25+
/// </summary>
26+
internal bool Handled { get; set; }
27+
28+
/// <summary>
29+
/// The middleware Options.
30+
/// </summary>
1531
public OAuthIntrospectionOptions Options { get; }
1632
}
1733
}
Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,48 @@
1-
using Microsoft.AspNetCore.Http;
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
3+
* See https://github.com/aspnet-contrib/AspNet.Security.OAuth.Extensions for more information
4+
* concerning the license and the contributors participating to this project.
5+
*/
6+
7+
using JetBrains.Annotations;
8+
using Microsoft.AspNetCore.Authentication;
9+
using Microsoft.AspNetCore.Http;
210
using Newtonsoft.Json.Linq;
311

412
namespace AspNet.Security.OAuth.Introspection {
13+
/// <summary>
14+
/// Allows interception of the AuthenticationTicket creation process.
15+
/// </summary>
516
public class CreateTicketContext : BaseIntrospectionContext {
617
public CreateTicketContext(
7-
HttpContext context,
8-
OAuthIntrospectionOptions options,
9-
JObject payload)
18+
[NotNull]HttpContext context,
19+
[NotNull]OAuthIntrospectionOptions options,
20+
[NotNull]JObject payload)
1021
: base(context, options) {
1122
Payload = payload;
1223
}
1324

14-
public JObject Payload { get; set; }
25+
/// <summary>
26+
/// The payload from the introspection request to the authorization server.
27+
/// </summary>
28+
public JObject Payload { get; }
29+
30+
private AuthenticationTicket _ticket { get; set; }
31+
32+
/// <summary>
33+
/// An <see cref="AuthenticationTicket"/> created by the application.
34+
/// <remarks>
35+
/// Set this property to indicate that the application has handled the creation of the
36+
/// ticket. Set this property to null to instruct the middleware there was a failure
37+
/// during ticket creation.
38+
/// </remarks>
39+
/// </summary>
40+
public AuthenticationTicket Ticket {
41+
get { return _ticket; }
42+
set {
43+
Handled = true;
44+
_ticket = value;
45+
}
46+
}
1547
}
1648
}
Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
using System.Threading.Tasks;
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
3+
* See https://github.com/aspnet-contrib/AspNet.Security.OAuth.Extensions for more information
4+
* concerning the license and the contributors participating to this project.
5+
*/
26

3-
namespace AspNet.Security.OAuth.Introspection {
4-
public interface IOAuthIntrospectionEvents
5-
{
6-
/// <summary>
7-
/// Invoked when an access token is first received.
8-
/// </summary>
9-
Task AccessTokenReceived(AccessTokenReceivedContext context);
7+
using System.Threading.Tasks;
108

9+
namespace AspNet.Security.OAuth.Introspection {
10+
/// <summary>
11+
/// Allows customization of introspection handling within the middleware.
12+
/// </summary>
13+
public interface IOAuthIntrospectionEvents {
1114
/// <summary>
12-
/// Invoked if exceptions are thrown during request processing. The exceptions will be re-thrown after this event unless suppressed.
15+
/// Invoked when a token is to be parsed from a newly-received request.
1316
/// </summary>
14-
Task AuthenticationFailed(AuthenticationFailedContext context);
17+
Task ParseAccessToken(ParseAccessTokenContext context);
1518

1619
/// <summary>
1720
/// Invoked when a ticket is to be created from an introspection response.
@@ -24,13 +27,8 @@ public interface IOAuthIntrospectionEvents
2427
Task RequestTokenIntrospection(RequestTokenIntrospectionContext context);
2528

2629
/// <summary>
27-
/// Invoked after processing, when a token has been validated.
28-
/// </summary>
29-
Task TokenValidated(TokenValidatedContext context);
30-
31-
/// <summary>
32-
/// Invoked when audiences are to be validated for a message.
30+
/// Invoked when a token is to be validated, before final processing.
3331
/// </summary>
34-
Task ValidateAudience(ValidateAudienceContext context);
32+
Task ValidateToken(ValidateTokenContext context);
3533
}
3634
}
Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,55 @@
1-
using System;
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
3+
* See https://github.com/aspnet-contrib/AspNet.Security.OAuth.Extensions for more information
4+
* concerning the license and the contributors participating to this project.
5+
*/
6+
7+
using System;
28
using System.Threading.Tasks;
39

410
namespace AspNet.Security.OAuth.Introspection {
5-
public class OAuthIntrospectionEvents : IOAuthIntrospectionEvents
6-
{
7-
/// <summary>
8-
/// Invoked when an access token is first received.
9-
/// </summary>
10-
public Func<AccessTokenReceivedContext, Task> OnAccessTokenReceived { get; set; } = context => Task.FromResult(0);
11-
12-
/// <summary>
13-
/// Invoked if exceptions are thrown during request processing. The exceptions will be re-thrown after this event unless suppressed.
14-
/// </summary>
15-
public Func<AuthenticationFailedContext, Task> OnAuthenticationFailed { get; set; } = context => Task.FromResult(0);
16-
11+
/// <summary>
12+
/// Allows customization of introspection handling within the middleware.
13+
/// </summary>
14+
public class OAuthIntrospectionEvents : IOAuthIntrospectionEvents {
1715
/// <summary>
1816
/// Invoked when a ticket is to be created from an introspection response.
1917
/// </summary>
2018
public Func<CreateTicketContext, Task> OnCreateTicket { get; set; } = context => Task.FromResult(0);
2119

2220
/// <summary>
23-
/// Invoked when a token is to be sent to the authorization server for introspection.
21+
/// Invoked when a token is to be parsed from a newly-received request.
2422
/// </summary>
25-
public Func<RequestTokenIntrospectionContext, Task> OnRequestTokenIntrospection { get; set; } = context => Task.FromResult(0);
23+
public Func<ParseAccessTokenContext, Task> OnParseAccessToken { get; set; } = context => Task.FromResult(0);
2624

2725
/// <summary>
28-
/// Invoked after processing, when a token has been validated.
29-
/// </summary>
30-
public Func<TokenValidatedContext, Task> OnTokenValidated { get; set; } = context => Task.FromResult(0);
31-
32-
/// <summary>
33-
/// Invoked when audiences are to be validated for a message.
34-
/// </summary>
35-
public Func<ValidateAudienceContext, Task> OnValidateAudience { get; set; } = context => Task.FromResult(0);
36-
37-
/// <summary>
38-
/// Invoked when an access token is first received.
26+
/// Invoked when a token is to be sent to the authorization server for introspection.
3927
/// </summary>
40-
public virtual Task AccessTokenReceived(AccessTokenReceivedContext context) => OnAccessTokenReceived(context);
28+
public Func<RequestTokenIntrospectionContext, Task> OnRequestTokenIntrospection { get; set; } = context => Task.FromResult(0);
4129

4230
/// <summary>
43-
/// Invoked if exceptions are thrown during request processing. The exceptions will be re-thrown after this event unless suppressed.
31+
/// Invoked when a token is to be validated, before final processing.
4432
/// </summary>
45-
public virtual Task AuthenticationFailed(AuthenticationFailedContext context) => OnAuthenticationFailed(context);
33+
public Func<ValidateTokenContext, Task> OnValidateToken { get; set; } = context => Task.FromResult(0);
4634

4735
/// <summary>
4836
/// Invoked when a ticket is to be created from an introspection response.
4937
/// </summary>
5038
public virtual Task CreateTicket(CreateTicketContext context) => OnCreateTicket(context);
5139

5240
/// <summary>
53-
/// Invoked when a token is to be sent to the authorization server for introspection.
41+
/// Invoked when a token is to be parsed from a newly-received request.
5442
/// </summary>
55-
public virtual Task RequestTokenIntrospection(RequestTokenIntrospectionContext context) => OnRequestTokenIntrospection(context);
43+
public virtual Task ParseAccessToken(ParseAccessTokenContext context) => OnParseAccessToken(context);
5644

5745
/// <summary>
58-
/// Invoked after processing, when a token has been validated.
46+
/// Invoked when a token is to be sent to the authorization server for introspection.
5947
/// </summary>
60-
public virtual Task TokenValidated(TokenValidatedContext context) => OnTokenValidated(context);
48+
public virtual Task RequestTokenIntrospection(RequestTokenIntrospectionContext context) => OnRequestTokenIntrospection(context);
6149

6250
/// <summary>
63-
/// Invoked when audiences are to be validated for a message.
51+
/// Invoked when a token is to be validated, before final processing.
6452
/// </summary>
65-
public virtual Task ValidateAudience(ValidateAudienceContext context) => OnValidateAudience(context);
53+
public virtual Task ValidateToken(ValidateTokenContext context) => OnValidateToken(context);
6654
}
6755
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
3+
* See https://github.com/aspnet-contrib/AspNet.Security.OAuth.Extensions for more information
4+
* concerning the license and the contributors participating to this project.
5+
*/
6+
7+
using JetBrains.Annotations;
8+
using Microsoft.AspNetCore.Http;
9+
10+
namespace AspNet.Security.OAuth.Introspection {
11+
/// <summary>
12+
/// Allows custom parsing of access tokens from requests.
13+
/// </summary>
14+
public class ParseAccessTokenContext : BaseIntrospectionContext {
15+
public ParseAccessTokenContext(
16+
[NotNull]HttpContext context,
17+
[NotNull]OAuthIntrospectionOptions options)
18+
: base(context, options) {
19+
}
20+
21+
private string _token { get; set; }
22+
23+
/// <summary>
24+
/// Gets or sets the access token.
25+
/// <remarks>
26+
/// Setting this property indicates to the middleware that the request has been processed
27+
/// and a token extracted. Setting this to null will invalidate the token.
28+
/// </remarks>
29+
/// </summary>
30+
public string Token {
31+
get { return _token; }
32+
set {
33+
Handled = true;
34+
_token = value;
35+
}
36+
}
37+
}
38+
}
Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,53 @@
1-
using Microsoft.AspNetCore.Http;
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
3+
* See https://github.com/aspnet-contrib/AspNet.Security.OAuth.Extensions for more information
4+
* concerning the license and the contributors participating to this project.
5+
*/
6+
7+
using System.Net.Http;
8+
using Microsoft.AspNetCore.Http;
29
using Newtonsoft.Json.Linq;
10+
using JetBrains.Annotations;
311

412
namespace AspNet.Security.OAuth.Introspection {
13+
/// <summary>
14+
/// Allows for custom handling of the call to the Authorization Server's Introspection endpoint.
15+
/// </summary>
516
public class RequestTokenIntrospectionContext : BaseIntrospectionContext {
617
public RequestTokenIntrospectionContext(
7-
HttpContext context,
8-
OAuthIntrospectionOptions options,
9-
string token)
18+
[NotNull]HttpContext context,
19+
[NotNull]OAuthIntrospectionOptions options,
20+
[NotNull]string token)
1021
: base(context, options) {
1122
Token = token;
1223
}
1324

25+
/// <summary>
26+
/// An <see cref="HttpClient"/> for use by the application to call the authorization server.
27+
/// </summary>
28+
public HttpClient Client => Options.HttpClient;
29+
30+
/// <summary>
31+
/// The access token parsed from the client request.
32+
/// </summary>
1433
public string Token { get; }
1534

16-
public JObject Payload { get; set; }
35+
private JObject _payload { get; set; }
36+
37+
/// <summary>
38+
/// The data retrieved from the call to the introspection endpoint on the authorization server.
39+
/// <remarks>
40+
/// Set this property to indicate that the introspection call was handled
41+
/// by the application. Set this property to null to instruct the middleware
42+
/// to indicate a failure.
43+
/// </remarks>
44+
/// </summary>
45+
public JObject Payload {
46+
get { return _payload; }
47+
set {
48+
Handled = true;
49+
Payload = value;
50+
}
51+
}
1752
}
1853
}

src/AspNet.Security.OAuth.Introspection/Events/TokenValidatedContext.cs

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

0 commit comments

Comments
 (0)