Skip to content

Commit bdcea7c

Browse files
cleanup
1 parent 43c0db6 commit bdcea7c

8 files changed

Lines changed: 26 additions & 34 deletions

src/Infrastructure/CacheUtils.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ public static class CacheUtils
1818
/// <returns></returns>
1919
public static Func<OAuth2IntrospectionOptions,string, string> CacheKeyFromToken()
2020
{
21-
return (options, token) =>
22-
{
23-
return $"{options.CacheKeyPrefix}{token.Sha256()}";
24-
};
21+
return (options, token) => $"{options.CacheKeyPrefix}{token.Sha256()}";
2522
}
2623
}
2724
}

src/Infrastructure/TokenRetrieval.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static class TokenRetrieval
1919
/// <returns></returns>
2020
public static Func<HttpRequest, string> FromAuthorizationHeader(string scheme = "Bearer")
2121
{
22-
return (request) =>
22+
return request =>
2323
{
2424
string authorization = request.Headers["Authorization"].FirstOrDefault();
2525

src/OAuth2IntrospectionHandler.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class OAuth2IntrospectionHandler : AuthenticationHandler<OAuth2Introspect
2525
private readonly IDistributedCache _cache;
2626
private readonly ILogger<OAuth2IntrospectionHandler> _logger;
2727

28-
static readonly ConcurrentDictionary<string, Lazy<Task<TokenIntrospectionResponse>>> IntrospectionDictionary =
28+
private static readonly ConcurrentDictionary<string, Lazy<Task<TokenIntrospectionResponse>>> IntrospectionDictionary =
2929
new ConcurrentDictionary<string, Lazy<Task<TokenIntrospectionResponse>>>();
3030

3131
/// <summary>
@@ -55,8 +55,8 @@ public OAuth2IntrospectionHandler(
5555
/// </summary>
5656
protected new OAuth2IntrospectionEvents Events
5757
{
58-
get { return (OAuth2IntrospectionEvents)base.Events; }
59-
set { base.Events = value; }
58+
get => (OAuth2IntrospectionEvents)base.Events;
59+
set => base.Events = value;
6060
}
6161

6262
/// <inheritdoc/>
@@ -68,7 +68,7 @@ public OAuth2IntrospectionHandler(
6868
/// <returns></returns>
6969
protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
7070
{
71-
string token = Options.TokenRetriever(Context.Request);
71+
var token = Options.TokenRetriever(Context.Request);
7272

7373
// no token - nothing to do here
7474
if (token.IsMissing())
@@ -167,12 +167,7 @@ private static async Task<AuthenticateResult> ReportNonSuccessAndReturn(
167167

168168
await events.AuthenticationFailed(authenticationFailedContext);
169169

170-
if (authenticationFailedContext.Result != null)
171-
{
172-
return authenticationFailedContext.Result;
173-
}
174-
175-
return AuthenticateResult.Fail(error);
170+
return authenticationFailedContext.Result ?? AuthenticateResult.Fail(error);
176171
}
177172

178173
private static async Task<TokenIntrospectionResponse> LoadClaimsForToken(

src/OAuth2IntrospectionOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ public OAuth2IntrospectionOptions()
128128
/// </summary>
129129
public new OAuth2IntrospectionEvents Events
130130
{
131-
get { return (OAuth2IntrospectionEvents)base.Events; }
132-
set { base.Events = value; }
131+
get => (OAuth2IntrospectionEvents)base.Events;
132+
set => base.Events = value;
133133
}
134134

135135
internal AsyncLazy<HttpClient> IntrospectionClient { get; set; }

test/Tests/Configuration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class Configuration
1717
[Fact]
1818
public void Empty_Options()
1919
{
20-
Action act = () => PipelineFactory.CreateClient((options) => { })
20+
Action act = () => PipelineFactory.CreateClient(options => { })
2121
.GetAsync("http://test").GetAwaiter().GetResult();
2222

2323
act.Should().Throw<InvalidOperationException>()

test/Tests/Introspection.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class Introspection
2424
private static readonly string clientId = "client";
2525
private static readonly string clientSecret = "secret";
2626

27-
readonly Action<OAuth2IntrospectionOptions> _options = (o) =>
27+
private readonly Action<OAuth2IntrospectionOptions> _options = o =>
2828
{
2929
o.Authority = "https://authority.com";
3030
o.DiscoveryPolicy.RequireKeySet = false;
@@ -38,7 +38,7 @@ public async Task Unauthorized_Client()
3838
{
3939
var handler = new IntrospectionEndpointHandler(IntrospectionEndpointHandler.Behavior.Unauthorized);
4040

41-
var client = PipelineFactory.CreateClient((o) => _options(o), handler);
41+
var client = PipelineFactory.CreateClient(o => _options(o), handler);
4242
client.SetBearerToken("sometoken");
4343

4444
var result = await client.GetAsync("http://test");
@@ -69,7 +69,7 @@ public async Task ActiveToken_With_ClientAssertion(int ttl, string assertion1, s
6969
var handler = new IntrospectionEndpointHandler(IntrospectionEndpointHandler.Behavior.Active);
7070
var count = 0;
7171

72-
var client = PipelineFactory.CreateClient((o) =>
72+
var client = PipelineFactory.CreateClient(o =>
7373
{
7474
_options(o);
7575
o.ClientSecret = null;
@@ -114,7 +114,7 @@ public async Task Active_token_with_inline_event_events_should_be_called()
114114
bool? validatedCalled = null;
115115
bool? failureCalled = null;
116116

117-
var client = PipelineFactory.CreateClient((o) =>
117+
var client = PipelineFactory.CreateClient(o =>
118118
{
119119
_options(o);
120120

@@ -147,7 +147,7 @@ public async Task Active_token_with_inline_event_events_should_be_called()
147147
public async Task ActiveToken_With_Caching_Ttl_Longer_Than_Duration()
148148
{
149149
var handler = new IntrospectionEndpointHandler(IntrospectionEndpointHandler.Behavior.Active, TimeSpan.FromHours(1));
150-
var client = PipelineFactory.CreateClient((o) =>
150+
var client = PipelineFactory.CreateClient(o =>
151151
{
152152
_options(o);
153153

@@ -170,7 +170,7 @@ public async Task ActiveToken_With_Caching_Ttl_Shorter_Than_Duration()
170170
{
171171
var handler = new IntrospectionEndpointHandler(IntrospectionEndpointHandler.Behavior.Active, TimeSpan.FromMinutes(5));
172172

173-
var client = PipelineFactory.CreateClient((o) =>
173+
var client = PipelineFactory.CreateClient(o =>
174174
{
175175
_options(o);
176176

@@ -192,7 +192,7 @@ public async Task InactiveToken()
192192
{
193193
var handler = new IntrospectionEndpointHandler(IntrospectionEndpointHandler.Behavior.Inactive);
194194

195-
var client = PipelineFactory.CreateClient((o) => _options(o), handler);
195+
var client = PipelineFactory.CreateClient(o => _options(o), handler);
196196
client.SetBearerToken("sometoken");
197197

198198
var result = await client.GetAsync("http://test");
@@ -206,7 +206,7 @@ public async Task InActive_token_with_inline_event_events_should_be_called()
206206
bool? validatedCalled = null;
207207
bool? failureCalled = null;
208208

209-
var client = PipelineFactory.CreateClient((o) =>
209+
var client = PipelineFactory.CreateClient(o =>
210210
{
211211
_options(o);
212212

@@ -241,7 +241,7 @@ public async Task ActiveToken_With_SavedToken()
241241
var expectedToken = "expected_token";
242242
var handler = new IntrospectionEndpointHandler(IntrospectionEndpointHandler.Behavior.Active);
243243

244-
var client = PipelineFactory.CreateClient((o) =>
244+
var client = PipelineFactory.CreateClient(o =>
245245
{
246246
_options(o);
247247

@@ -265,7 +265,7 @@ public async Task ActiveToken_With_SavedToken_And_Caching()
265265
var expectedToken = "expected_token";
266266
var handler = new IntrospectionEndpointHandler(IntrospectionEndpointHandler.Behavior.Active, TimeSpan.FromHours(1));
267267

268-
var server = PipelineFactory.CreateServer((o) =>
268+
var server = PipelineFactory.CreateServer(o =>
269269
{
270270
_options(o);
271271

@@ -296,7 +296,7 @@ public async Task ActiveToken_With_SavedToken_And_Caching_With_Cache_Key_Prefix(
296296
var cacheKeyPrefix = "KeyPrefix";
297297
var handler = new IntrospectionEndpointHandler(IntrospectionEndpointHandler.Behavior.Active, TimeSpan.FromHours(1));
298298

299-
var server = PipelineFactory.CreateServer((o) =>
299+
var server = PipelineFactory.CreateServer(o =>
300300
{
301301
_options(o);
302302

@@ -327,7 +327,7 @@ public async Task Repeated_active_token_with_caching_enabled_should_hit_cache()
327327
var expectedToken = "expected_token";
328328
var handler = new IntrospectionEndpointHandler(IntrospectionEndpointHandler.Behavior.Active, TimeSpan.FromHours(1));
329329

330-
var server = PipelineFactory.CreateServer((o) =>
330+
var server = PipelineFactory.CreateServer(o =>
331331
{
332332
_options(o);
333333

@@ -355,7 +355,7 @@ public async Task Repeated_inactive_token_with_caching_enabled_should_hit_cache(
355355
var expectedToken = "expected_token";
356356
var handler = new IntrospectionEndpointHandler(IntrospectionEndpointHandler.Behavior.Inactive);
357357

358-
var server = PipelineFactory.CreateServer((o) =>
358+
var server = PipelineFactory.CreateServer(o =>
359359
{
360360
_options(o);
361361

@@ -383,7 +383,7 @@ public async Task ActiveToken_With_Discovery_Unavailable_On_First_Request()
383383
{
384384
var handler = new IntrospectionEndpointHandler(IntrospectionEndpointHandler.Behavior.Active);
385385

386-
var client = PipelineFactory.CreateClient((o) => _options(o), handler);
386+
var client = PipelineFactory.CreateClient(o => _options(o), handler);
387387
client.SetBearerToken("sometoken");
388388

389389
handler.IsDiscoveryFailureTest = true;

test/Tests/Util/IntrospectionEndpointHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace Tests.Util
1414
{
15-
class IntrospectionEndpointHandler : DelegatingHandler
15+
internal class IntrospectionEndpointHandler : DelegatingHandler
1616
{
1717
private readonly Behavior _behavior;
1818

test/Tests/Util/PipelineFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
namespace Tests.Util
1818
{
19-
class PipelineFactory
19+
internal static class PipelineFactory
2020
{
2121
public static TestServer CreateServer(Action<OAuth2IntrospectionOptions> options, DelegatingHandler backChannelHandler, bool addCaching = false)
2222
{

0 commit comments

Comments
 (0)