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

Commit 1b9a354

Browse files
committed
Add logging extensions for the OWIN/Katana validation/introspection middleware
1 parent 17e1c1f commit 1b9a354

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

src/Owin.Security.OAuth.Introspection/OAuthIntrospectionExtensions.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
using System;
88
using JetBrains.Annotations;
9+
using Microsoft.Extensions.Logging;
910
using Owin.Security.OAuth.Introspection;
1011

1112
namespace Owin
@@ -64,5 +65,33 @@ public static IAppBuilder UseOAuthIntrospection(
6465

6566
return app.Use<OAuthIntrospectionMiddleware>(app.Properties, options);
6667
}
68+
69+
/// <summary>
70+
/// Configures the OAuth2 introspection middleware to enable logging.
71+
/// </summary>
72+
/// <param name="options">The options used to configure the OAuth2 introspection middleware.</param>
73+
/// <param name="configuration">The delegate used to configure the logger factory.</param>
74+
/// <returns>The options used to configure the OAuth2 introspection middleware.</returns>
75+
public static OAuthIntrospectionOptions UseLogging(
76+
[NotNull] this OAuthIntrospectionOptions options,
77+
[NotNull] Action<ILoggerFactory> configuration)
78+
{
79+
if (options == null)
80+
{
81+
throw new ArgumentNullException(nameof(options));
82+
}
83+
84+
if (configuration == null)
85+
{
86+
throw new ArgumentNullException(nameof(configuration));
87+
}
88+
89+
var factory = new LoggerFactory();
90+
configuration(factory);
91+
92+
options.Logger = factory.CreateLogger<OAuthIntrospectionMiddleware>();
93+
94+
return options;
95+
}
6796
}
6897
}

src/Owin.Security.OAuth.Validation/OAuthValidationExtensions.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
using System;
88
using JetBrains.Annotations;
9+
using Microsoft.Extensions.Logging;
910
using Owin.Security.OAuth.Validation;
1011

1112
namespace Owin
@@ -79,5 +80,33 @@ public static IAppBuilder UseOAuthValidation(
7980

8081
return app.Use<OAuthValidationMiddleware>(app.Properties, options);
8182
}
83+
84+
/// <summary>
85+
/// Configures the OAuth2 validation middleware to enable logging.
86+
/// </summary>
87+
/// <param name="options">The options used to configure the OAuth2 validation middleware.</param>
88+
/// <param name="configuration">The delegate used to configure the logger factory.</param>
89+
/// <returns>The options used to configure the OAuth2 validation middleware.</returns>
90+
public static OAuthValidationOptions UseLogging(
91+
[NotNull] this OAuthValidationOptions options,
92+
[NotNull] Action<ILoggerFactory> configuration)
93+
{
94+
if (options == null)
95+
{
96+
throw new ArgumentNullException(nameof(options));
97+
}
98+
99+
if (configuration == null)
100+
{
101+
throw new ArgumentNullException(nameof(configuration));
102+
}
103+
104+
var factory = new LoggerFactory();
105+
configuration(factory);
106+
107+
options.Logger = factory.CreateLogger<OAuthValidationMiddleware>();
108+
109+
return options;
110+
}
82111
}
83112
}

0 commit comments

Comments
 (0)