Skip to content

Commit da5a24f

Browse files
committed
Resolve warnings.
1 parent cdb4800 commit da5a24f

File tree

67 files changed

+171
-162
lines changed

Some content is hidden

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

67 files changed

+171
-162
lines changed

Hosting/test/AppCoreNet.Extensions.Hosting.Plugins.Tests/PluginFacilityResolverTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,22 @@ public void RegistersFacilitiesWithExtensions()
3939
r =>
4040
r.ServiceType.FullName
4141
== "AppCoreNet.Extensions.Hosting.Plugins.TestPlugin.TestFacilityExtensionService"
42-
&& r.ImplementationType.FullName
42+
&& r.ImplementationType!.FullName
4343
== "AppCoreNet.Extensions.Hosting.Plugins.TestPlugin.TestFacilityExtensionService");
4444

4545
services.Should()
4646
.Contain(
4747
r =>
4848
r.ServiceType.FullName
4949
== "AppCoreNet.Extensions.Hosting.Plugins.TestPlugin.TestFacilityContractExtensionService"
50-
&& r.ImplementationType.FullName
50+
&& r.ImplementationType!.FullName
5151
== "AppCoreNet.Extensions.Hosting.Plugins.TestPlugin.TestFacilityContractExtensionService");
5252

5353
services.Should()
5454
.Contain(
5555
r =>
5656
r.ServiceType.FullName == "AppCoreNet.Extensions.Hosting.Plugins.TestPlugin2.TestFacilityExtensionService"
57-
&& r.ImplementationType.FullName == "AppCoreNet.Extensions.Hosting.Plugins.TestPlugin2.TestFacilityExtensionService");
57+
&& r.ImplementationType!.FullName == "AppCoreNet.Extensions.Hosting.Plugins.TestPlugin2.TestFacilityExtensionService");
5858
}
5959

6060
[Fact]
@@ -74,13 +74,13 @@ public void RegistersFacilities()
7474
.Contain(
7575
r =>
7676
r.ServiceType.FullName == "AppCoreNet.Extensions.Hosting.Plugins.TestPlugin.TestFacilityService"
77-
&& r.ImplementationType.FullName == "AppCoreNet.Extensions.Hosting.Plugins.TestPlugin.TestFacilityService");
77+
&& r.ImplementationType!.FullName == "AppCoreNet.Extensions.Hosting.Plugins.TestPlugin.TestFacilityService");
7878

7979
services.Should()
8080
.Contain(
8181
r =>
8282
r.ServiceType.FullName == "AppCoreNet.Extensions.Hosting.Plugins.TestPlugin2.TestFacilityService"
83-
&& r.ImplementationType.FullName == "AppCoreNet.Extensions.Hosting.Plugins.TestPlugin2.TestFacilityService");
83+
&& r.ImplementationType!.FullName == "AppCoreNet.Extensions.Hosting.Plugins.TestPlugin2.TestFacilityService");
8484
}
8585

8686
[Fact]
@@ -99,7 +99,7 @@ public void RegistersFacilityWithServices()
9999
services.Where(
100100
r =>
101101
r.ServiceType.FullName == "AppCoreNet.Extensions.Hosting.Plugins.TestPlugin.TestFacilityService"
102-
&& r.ImplementationType.FullName == "AppCoreNet.Extensions.Hosting.Plugins.TestPlugin.TestFacilityService");
102+
&& r.ImplementationType!.FullName == "AppCoreNet.Extensions.Hosting.Plugins.TestPlugin.TestFacilityService");
103103

104104
facilityServices.Should()
105105
.HaveCount(2);

Hosting/test/AppCoreNet.Extensions.Hosting.Plugins.Tests/PluginServiceDescriptorResolverTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ public void RegistersServices()
3434
.Contain(
3535
r =>
3636
r.ServiceType.FullName == "AppCoreNet.Extensions.Hosting.IStartupTask"
37-
&& r.ImplementationType.FullName == "AppCoreNet.Extensions.Hosting.Plugins.TestPlugin.PublicStartupTask");
37+
&& r.ImplementationType!.FullName == "AppCoreNet.Extensions.Hosting.Plugins.TestPlugin.PublicStartupTask");
3838

3939
services.Should()
4040
.Contain(
4141
r =>
4242
r.ServiceType.FullName == "AppCoreNet.Extensions.Hosting.IStartupTask"
43-
&& r.ImplementationType.FullName == "AppCoreNet.Extensions.Hosting.Plugins.TestPlugin2.PublicStartupTask");
43+
&& r.ImplementationType!.FullName == "AppCoreNet.Extensions.Hosting.Plugins.TestPlugin2.PublicStartupTask");
4444
}
4545
}

Http/samples/Web/Controllers/HomeController.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System.Diagnostics;
2+
using System.Diagnostics.CodeAnalysis;
23
using System.Net.Http;
34
using System.Text.Json.Nodes;
5+
using System.Text.Json.Serialization;
46
using System.Threading.Tasks;
57
using Microsoft.AspNetCore.Authorization;
68
using Microsoft.AspNetCore.Mvc;
@@ -9,6 +11,10 @@
911

1012
namespace Web.Controllers;
1113

14+
[SuppressMessage(
15+
"IDisposableAnalyzers.Correctness",
16+
"IDISP001:Dispose created",
17+
Justification = "HttpClient instances are managed by IHttpClientFactory")]
1218
public class HomeController : Controller
1319
{
1420
private readonly IHttpClientFactory _httpClientFactory;
@@ -37,23 +43,23 @@ public IActionResult Error()
3743
}
3844

3945
[AllowAnonymous]
40-
public async Task<IActionResult> CallApiAsClient()
46+
public async Task<IActionResult> CallApiAsClientAsync()
4147
{
4248
HttpClient client = _httpClientFactory.CreateClient("api-client");
4349

4450
string response = await client.GetStringAsync("test");
45-
ViewBag.Json = JsonNode.Parse(response)!.ToString();
51+
ViewBag.Json = JsonNode.Parse(response) !.ToString();
4652

4753
return View("CallApi");
4854
}
4955

5056
[Authorize]
51-
public async Task<IActionResult> CallApiAsUser()
57+
public async Task<IActionResult> CallApiAsUserAsync()
5258
{
5359
HttpClient client = _httpClientFactory.CreateClient("api-user-client");
5460

5561
string response = await client.GetStringAsync("test");
56-
ViewBag.Json = JsonNode.Parse(response)!.ToString();
62+
ViewBag.Json = JsonNode.Parse(response) !.ToString();
5763

5864
return View("CallApi");
5965
}

Http/samples/Web/Program.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
options.Events.OnSigningOut = async e =>
2727
{
28-
//await e.HttpContext.RevokeUserRefreshTokenAsync();
28+
// await e.HttpContext.RevokeUserRefreshTokenAsync();
2929
};
3030
})
3131
.AddOpenIdConnect(
@@ -58,7 +58,7 @@
5858
options.TokenValidationParameters = new TokenValidationParameters
5959
{
6060
NameClaimType = "name",
61-
RoleClaimType = "role"
61+
RoleClaimType = "role",
6262
};
6363
});
6464

@@ -99,6 +99,7 @@
9999
if (!app.Environment.IsDevelopment())
100100
{
101101
app.UseExceptionHandler("/Home/Error");
102+
102103
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
103104
app.UseHsts();
104105
}

Http/src/AppCoreNet.Extensions.Http.Authentication.OAuth.AspNetCore/AuthenticationSchemeOAuthClientOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
// Licensed under the MIT license.
22
// Copyright (c) The AppCore .NET project.
33

4-
namespace AppCore.Extensions.Http.Authentication.OAuth.AspNetCore;
4+
namespace AppCoreNet.Extensions.Http.Authentication.OAuth.AspNetCore;
55

66
/// <summary>
77
/// Provides the options how to derive <see cref="OAuthClientOptions"/> from authentication scheme options.
88
/// </summary>
99
public abstract class AuthenticationSchemeOAuthClientOptions : AuthenticationSchemeOptions
1010
{
1111
/// <summary>
12-
/// Sets the scheme name of an authentication handler, if the client configuration should be derived from it.
12+
/// Gets or sets the scheme name of an authentication handler, if the client configuration should be derived from it.
1313
/// This will fallback to the default challenge scheme if left empty.
1414
/// </summary>
1515
public string? Scheme { get; set; }

Http/src/AppCoreNet.Extensions.Http.Authentication.OAuth.AspNetCore/AuthenticationSchemeOAuthClientOptionsResolver.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
using System;
55
using System.Threading.Tasks;
66
using AppCoreNet.Diagnostics;
7-
87
using Microsoft.AspNetCore.Authentication;
98
using Microsoft.Extensions.Options;
109

11-
namespace AppCore.Extensions.Http.Authentication.OAuth.AspNetCore;
10+
namespace AppCoreNet.Extensions.Http.Authentication.OAuth.AspNetCore;
1211

1312
using IAuthenticationSchemeProvider = Microsoft.AspNetCore.Authentication.IAuthenticationSchemeProvider;
1413

@@ -76,7 +75,6 @@ protected AuthenticationSchemeOAuthClientOptionsResolver(
7675
{
7776
throw new InvalidOperationException(
7877
"The authentication scheme handler configured for getting client configuration is not compatible.");
79-
8078
}
8179

8280
result = (T)(object)await GetOptionsFromSchemeAsync(
@@ -91,15 +89,15 @@ protected AuthenticationSchemeOAuthClientOptionsResolver(
9189
/// <summary>
9290
/// Gets the name of the authentication scheme.
9391
/// </summary>
94-
/// <param name="options"></param>
95-
/// <returns></returns>
92+
/// <param name="options">The <see cref="AuthenticationSchemeOptions"/>.</param>
93+
/// <returns>The authentication scheme name.</returns>
9694
protected abstract string? GetSchemeName(TClientOptions options);
9795

9896
/// <summary>
9997
/// Must be implemented to resolve the <see cref="OAuthClientOptions"/> from the authentication scheme options.
10098
/// </summary>
10199
/// <param name="clientOptions">The <see cref="AuthenticationSchemeOAuthClientOptions"/>.</param>
102100
/// <param name="options">The <see cref="RemoteAuthenticationOptions"/>.</param>
103-
/// <returns></returns>
101+
/// <returns>An asynchronous task that returns the <see cref="OAuthClientOptions"/>.</returns>
104102
protected abstract Task<OAuthClientOptions> GetOptionsFromSchemeAsync(TClientOptions clientOptions, TOptions options);
105103
}

Http/src/AppCoreNet.Extensions.Http.Authentication.OAuth.AspNetCore/AuthenticationSessionOAuthUserTokenStore.cs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77
using System.Threading;
88
using System.Threading.Tasks;
99
using AppCoreNet.Diagnostics;
10-
1110
using Microsoft.AspNetCore.Authentication;
1211
using Microsoft.AspNetCore.Http;
1312
using Microsoft.Extensions.DependencyInjection;
1413
using Microsoft.Extensions.Logging;
1514
using Microsoft.Extensions.Options;
1615

17-
namespace AppCore.Extensions.Http.Authentication.OAuth.AspNetCore;
16+
namespace AppCoreNet.Extensions.Http.Authentication.OAuth.AspNetCore;
1817

1918
/// <summary>
2019
/// Provides the base class for <see cref="IOAuthUserTokenStore"/> which stores tokens in the authentication
@@ -30,7 +29,7 @@ public abstract class AuthenticationSessionOAuthUserTokenStore<TOptions> : IOAut
3029

3130
// per-request cache so that if SignInAsync is used, we won't re-read the old/cached AuthenticateResult from the handler
3231
// this requires this service to be added as scoped to the DI system
33-
private readonly Dictionary<string, AuthenticateResult> _cache = new();
32+
private readonly Dictionary<string, AuthenticateResult> _cache = new ();
3433

3534
/// <summary>
3635
/// Initializes a new instance of the <see cref="AuthenticationSessionOAuthUserTokenStore{TOptions}"/> class.
@@ -61,7 +60,7 @@ private HttpContext GetHttpContext()
6160
return httpContext;
6261
}
6362

64-
private async Task<string> GetSignInScheme(HttpContext context, TOptions options)
63+
private async Task<string> GetSignInSchemeAsync(HttpContext context, TOptions options)
6564
{
6665
string? scheme = string.IsNullOrWhiteSpace(options.SignInScheme)
6766
? options.SignInScheme
@@ -92,14 +91,13 @@ private async Task<string> GetSignInScheme(HttpContext context, TOptions options
9291

9392
if (!result.Succeeded)
9493
{
95-
_logger.LogError("Cannot authenticate scheme: {schemeName}", signInScheme);
94+
_logger.LogError("Cannot authenticate scheme: {SchemeName}", signInScheme);
9695
return null;
9796
}
9897

9998
if (result.Properties == null)
10099
{
101-
_logger.LogError("Authentication result properties are null for scheme: {schemeName}",
102-
signInScheme);
100+
_logger.LogError("Authentication result properties are null for scheme: {SchemeName}", signInScheme);
103101

104102
return null;
105103
}
@@ -128,7 +126,7 @@ public async Task StoreTokenAsync(
128126

129127
HttpContext httpContext = GetHttpContext();
130128
TOptions options = _optionsMonitor.Get(scheme.Name);
131-
string signInScheme = await GetSignInScheme(httpContext, options);
129+
string signInScheme = await GetSignInSchemeAsync(httpContext, options);
132130

133131
AuthenticateResult? result = await TryAuthenticateAsync(httpContext, signInScheme);
134132
if (result == null)
@@ -150,10 +148,10 @@ public async Task StoreTokenAsync(
150148
/// <summary>
151149
/// Stores the token in the authentication session.
152150
/// </summary>
153-
/// <param name="principal"></param>
154-
/// <param name="properties"></param>
155-
/// <param name="token"></param>
156-
/// <param name="options"></param>
151+
/// <param name="principal">The <see cref="ClaimsPrincipal"/>.</param>
152+
/// <param name="properties">The <see cref="AuthenticationProperties"/>.</param>
153+
/// <param name="token">The <see cref="OAuthUserToken"/>.</param>
154+
/// <param name="options">The <see cref="OAuthUserOptions"/>.</param>
157155
protected abstract void StoreToken(
158156
ClaimsPrincipal principal,
159157
AuthenticationProperties properties,
@@ -173,7 +171,7 @@ public async Task<OAuthUserToken> GetTokenAsync(
173171

174172
HttpContext httpContext = GetHttpContext();
175173
TOptions options = _optionsMonitor.Get(scheme.Name);
176-
string signInScheme = await GetSignInScheme(httpContext, options);
174+
string signInScheme = await GetSignInSchemeAsync(httpContext, options);
177175

178176
AuthenticateResult? result = await TryAuthenticateAsync(httpContext, signInScheme);
179177
if (result == null)
@@ -185,10 +183,10 @@ public async Task<OAuthUserToken> GetTokenAsync(
185183
/// <summary>
186184
/// Gets the token from the authentication session.
187185
/// </summary>
188-
/// <param name="principal"></param>
189-
/// <param name="properties"></param>
190-
/// <param name="options"></param>
191-
/// <returns></returns>
186+
/// <param name="principal">The <see cref="ClaimsPrincipal"/>.</param>
187+
/// <param name="properties">The <see cref="AuthenticationProperties"/>.</param>
188+
/// <param name="options">The <see cref="OAuthUserOptions"/>.</param>
189+
/// <returns>The <see cref="OAuthUserToken"/>.</returns>
192190
protected abstract OAuthUserToken GetToken(
193191
ClaimsPrincipal principal,
194192
AuthenticationProperties properties,

Http/src/AppCoreNet.Extensions.Http.Authentication.OAuth.AspNetCore/DependencyInjection/OAuthHttpClientAuthenticationBuilderExtensions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
using System;
55
using AppCoreNet.Diagnostics;
6-
using AppCore.Extensions.Http.Authentication.OAuth;
6+
using AppCoreNet.Extensions.Http.Authentication.OAuth;
77

88
// ReSharper disable once CheckNamespace
99
namespace AppCoreNet.Extensions.DependencyInjection;
@@ -19,8 +19,8 @@ public static class OAuthHttpClientAuthenticationBuilderExtensions
1919
/// </summary>
2020
/// <param name="builder">The <see cref="IHttpClientAuthenticationBuilder"/>.</param>
2121
/// <param name="scheme">The name of the client authentication scheme.</param>
22-
/// <param name="configure"></param>
23-
/// <returns></returns>
22+
/// <param name="configure">A delegate to configure the <see cref="OAuthClientFromAuthenticationSchemeBuilder"/>.</param>
23+
/// <returns>The <see cref="IHttpClientAuthenticationBuilder"/> to allow chaining.</returns>
2424
public static IHttpClientAuthenticationBuilder AddOAuthClientForScheme(
2525
this IHttpClientAuthenticationBuilder builder,
2626
string scheme,
@@ -40,8 +40,8 @@ public static IHttpClientAuthenticationBuilder AddOAuthClientForScheme(
4040
/// authentication scheme.
4141
/// </summary>
4242
/// <param name="builder">The <see cref="IHttpClientAuthenticationBuilder"/>.</param>
43-
/// <param name="configure"></param>
44-
/// <returns></returns>
43+
/// <param name="configure">A delegate to configure the <see cref="OAuthClientFromAuthenticationSchemeBuilder"/>.</param>
44+
/// <returns>The <see cref="IHttpClientAuthenticationBuilder"/> to allow chaining.</returns>
4545
public static IHttpClientAuthenticationBuilder AddOAuthClientForScheme(
4646
this IHttpClientAuthenticationBuilder builder,
4747
Action<IOAuthClientFromAuthenticationSchemeBuilder> configure)

Http/src/AppCoreNet.Extensions.Http.Authentication.OAuth.AspNetCore/IOAuthUserTokenService.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System.Threading;
66
using System.Threading.Tasks;
77

8-
namespace AppCore.Extensions.Http.Authentication.OAuth.AspNetCore;
8+
namespace AppCoreNet.Extensions.Http.Authentication.OAuth.AspNetCore;
99

1010
/// <summary>
1111
/// Abstraction for the OAuth user token service.
@@ -19,8 +19,8 @@ public interface IOAuthUserTokenService
1919
/// <param name="scheme">The <see cref="AuthenticationScheme"/>.</param>
2020
/// <param name="user">The user.</param>
2121
/// <param name="parameters">Optional parameters.</param>
22-
/// <param name="cancellationToken"></param>
23-
/// <returns></returns>
22+
/// <param name="cancellationToken">Optional cancellation token.</param>
23+
/// <returns>A task returning the <see cref="OAuthUserToken"/>.</returns>
2424
Task<OAuthUserToken> GetAccessTokenAsync(
2525
AuthenticationScheme scheme,
2626
ClaimsPrincipal user,
@@ -32,7 +32,8 @@ Task<OAuthUserToken> GetAccessTokenAsync(
3232
/// </summary>
3333
/// <param name="scheme">The <see cref="AuthenticationScheme"/>.</param>
3434
/// <param name="user">The user.</param>
35-
/// <param name="cancellationToken"></param>
35+
/// <param name="cancellationToken">Optional cancellation token.</param>
36+
/// <returns>Asynchronous task.</returns>
3637
Task RevokeRefreshTokenAsync(
3738
AuthenticationScheme scheme,
3839
ClaimsPrincipal user,

Http/src/AppCoreNet.Extensions.Http.Authentication.OAuth.AspNetCore/IOAuthUserTokenStore.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System.Threading;
66
using System.Threading.Tasks;
77

8-
namespace AppCore.Extensions.Http.Authentication.OAuth.AspNetCore;
8+
namespace AppCoreNet.Extensions.Http.Authentication.OAuth.AspNetCore;
99

1010
/// <summary>
1111
/// Abstraction for the OAuth user token store.
@@ -19,6 +19,7 @@ public interface IOAuthUserTokenStore
1919
/// <param name="user">The <see cref="ClaimsPrincipal"/>.</param>
2020
/// <param name="token">The <see cref="OAuthUserToken"/>.</param>
2121
/// <param name="cancellationToken">Optional <see cref="CancellationToken"/>.</param>
22+
/// <returns>An asynchronous task.</returns>
2223
Task StoreTokenAsync(
2324
AuthenticationScheme scheme,
2425
ClaimsPrincipal user,
@@ -31,6 +32,7 @@ Task StoreTokenAsync(
3132
/// <param name="scheme">The <see cref="AuthenticationScheme"/>.</param>
3233
/// <param name="user">The <see cref="ClaimsPrincipal"/>.</param>
3334
/// <param name="cancellationToken">Optional <see cref="CancellationToken"/>.</param>
35+
/// <returns>An asynchronous task returning the <see cref="OAuthUserToken"/>.</returns>
3436
Task<OAuthUserToken> GetTokenAsync(
3537
AuthenticationScheme scheme,
3638
ClaimsPrincipal user,
@@ -42,6 +44,7 @@ Task<OAuthUserToken> GetTokenAsync(
4244
/// <param name="scheme">The <see cref="AuthenticationScheme"/>.</param>
4345
/// <param name="user">The <see cref="ClaimsPrincipal"/>.</param>
4446
/// <param name="cancellationToken">Optional <see cref="CancellationToken"/>.</param>
47+
/// <returns>An asynchronous task.</returns>
4548
Task ClearTokenAsync(
4649
AuthenticationScheme scheme,
4750
ClaimsPrincipal user,

0 commit comments

Comments
 (0)