Skip to content

Commit de08ca0

Browse files
authored
Merge pull request #197 from DuendeSoftware/dgb/update-editorconfig-20250428162925
Update .editorconfig
2 parents 1901382 + eeaf3dd commit de08ca0

34 files changed

+338
-66
lines changed

.editorconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ indent_style = space
77
insert_final_newline = true
88

99
[*.cs]
10+
csharp_prefer_braces = true
1011
csharp_style_expression_bodied_accessors = true
1112
csharp_style_expression_bodied_constructors = true
1213
csharp_style_expression_bodied_indexers = true
@@ -23,6 +24,7 @@ csharp_style_var_when_type_is_apparent = true
2324
dotnet_diagnostic.IDE0003.severity = error # Remove this or Me qualification
2425
dotnet_diagnostic.IDE0005.severity = error # Remove unnecessary using directives
2526
dotnet_diagnostic.IDE0007.severity = error # Use var instead of explicit type
27+
dotnet_diagnostic.IDE0011.severity = error # Add braces
2628
dotnet_diagnostic.IDE0021.severity = error # Use expression body for constructors
2729
dotnet_diagnostic.IDE0022.severity = error # Use expression body for methods
2830
dotnet_diagnostic.IDE0023.severity = error # Use expression body for conversion operators

access-token-management/src/AccessTokenManagement/HybridClientCredentialsTokenCache.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ public async Task<ClientCredentialsToken> GetOrCreateAsync(
116116
public async Task<ClientCredentialsToken?> GetAsync(string clientName, TokenRequestParameters requestParameters,
117117
CancellationToken cancellationToken = default)
118118
{
119-
if (clientName is null) throw new ArgumentNullException(nameof(clientName));
119+
if (clientName is null)
120+
{
121+
throw new ArgumentNullException(nameof(clientName));
122+
}
120123

121124
var cacheKey = cacheKeyGenerator.GenerateKey(clientName, requestParameters);
122125

access-token-management/test/AccessTokenManagement.Tests/Framework/GenericHost.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,20 @@ public T Resolve<T>()
4343
public string Url(string? path = null)
4444
{
4545
path = path ?? string.Empty;
46-
if (!path.StartsWith("/")) path = "/" + path;
46+
if (!path.StartsWith("/"))
47+
{
48+
path = "/" + path;
49+
}
50+
4751
return BaseAddress + path;
4852
}
4953

5054
public async Task InitializeAsync()
5155
{
52-
if (Server != null) throw new InvalidOperationException("Already initialized");
56+
if (Server != null)
57+
{
58+
throw new InvalidOperationException("Already initialized");
59+
}
5360

5461
var hostBuilder = new HostBuilder()
5562
.ConfigureWebHost(builder =>
@@ -184,9 +191,13 @@ public async ValueTask DisposeAsync()
184191
static async ValueTask CastAndDispose(IDisposable resource)
185192
{
186193
if (resource is IAsyncDisposable resourceAsyncDisposable)
194+
{
187195
await resourceAsyncDisposable.DisposeAsync();
196+
}
188197
else
198+
{
189199
resource?.Dispose();
200+
}
190201
}
191202
}
192203
}

access-token-management/test/AccessTokenManagement.Tests/Framework/TestBrowserClient.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,11 @@ public string? this[string key]
216216
{
217217
get
218218
{
219-
if (Inputs.ContainsKey(key)) return Inputs[key];
219+
if (Inputs.ContainsKey(key))
220+
{
221+
return Inputs[key];
222+
}
223+
220224
return null;
221225
}
222226
set => Inputs[key] = value;

access-token-management/test/AccessTokenManagement.Tests/Framework/TestDPoPProofService.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ public class TestDPoPProofService : IDPoPProofService
1111

1212
public Task<DPoPProof?> CreateProofTokenAsync(DPoPProofRequest request)
1313
{
14-
if (ProofToken == null) return Task.FromResult<DPoPProof?>(null);
14+
if (ProofToken == null)
15+
{
16+
return Task.FromResult<DPoPProof?>(null);
17+
}
18+
1519
Nonce = request.DPoPNonce;
1620
return Task.FromResult<DPoPProof?>(new DPoPProof { ProofToken = ProofToken + Nonce });
1721
}

access-token-management/test/AccessTokenManagement.Tests/TaskTimeoutExtensions.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ public static class TaskTimeoutExtensions
1010
private static TimeSpan IncreaseTimeoutIfDebuggerAttached(TimeSpan timeout)
1111
{
1212
// Wait a bit longer if the debugger is attached. This prevents timeouts during debugging.
13-
if (Debugger.IsAttached) return TimeSpan.FromMinutes(10);
13+
if (Debugger.IsAttached)
14+
{
15+
return TimeSpan.FromMinutes(10);
16+
}
1417

1518
return timeout == default ? TimeSpan.FromSeconds(2) : timeout;
1619
}
@@ -25,8 +28,11 @@ public static async Task ThrowOnTimeout(this Task task, TimeSpan timeout = defau
2528

2629
var resultTask = await Task.WhenAny(task, delayTask);
2730
if (resultTask == delayTask)
31+
{
2832
// Operation cancelled
2933
throw new OperationCanceledException();
34+
}
35+
3036
cts.Cancel();
3137

3238
await task;

identity-model-oidc-client/clients/ConsoleClientWithBrowser/Program.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,15 @@ private static async Task NextSteps(LoginResult result)
151151
Console.Write(menu);
152152
var key = Console.ReadKey();
153153

154-
if (key.Key == ConsoleKey.X) return;
155-
if (key.Key == ConsoleKey.C) await CallApi();
154+
if (key.Key == ConsoleKey.X)
155+
{
156+
return;
157+
}
158+
159+
if (key.Key == ConsoleKey.C)
160+
{
161+
await CallApi();
162+
}
156163
}
157164
}
158165

identity-model-oidc-client/clients/ConsoleClientWithBrowser/SystemBrowser.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ public class LoopbackHttpListener : IDisposable
110110
public LoopbackHttpListener(int port, string? path = null)
111111
{
112112
path = path ?? string.Empty;
113-
if (path.StartsWith("/")) path = path.Substring(1);
113+
if (path.StartsWith("/"))
114+
{
115+
path = path.Substring(1);
116+
}
114117

115118
_url = $"http://127.0.0.1:{port}/{path}";
116119

identity-model-oidc-client/clients/ConsoleClientWithBrowserAndDPoP/Program.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ private static string GetProofKey()
107107

108108
private static void ShowResult(LoginResult? result)
109109
{
110-
if (result == null) return;
110+
if (result == null)
111+
{
112+
return;
113+
}
111114

112115
if (result.IsError)
113116
{
@@ -142,8 +145,15 @@ private static async Task NextSteps()
142145
Console.Write(menu);
143146
var key = Console.ReadKey();
144147

145-
if (key.Key == ConsoleKey.X) return;
146-
if (key.Key == ConsoleKey.C) await CallApi();
148+
if (key.Key == ConsoleKey.X)
149+
{
150+
return;
151+
}
152+
153+
if (key.Key == ConsoleKey.C)
154+
{
155+
await CallApi();
156+
}
147157
}
148158
}
149159

identity-model-oidc-client/clients/ConsoleClientWithBrowserAndDPoP/SystemBrowser.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ public class LoopbackHttpListener : IDisposable
110110
public LoopbackHttpListener(int port, string? path = null)
111111
{
112112
path = path ?? string.Empty;
113-
if (path.StartsWith("/")) path = path.Substring(1);
113+
if (path.StartsWith("/"))
114+
{
115+
path = path.Substring(1);
116+
}
114117

115118
_url = $"http://127.0.0.1:{port}/{path}";
116119

identity-model-oidc-client/src/IdentityModel.OidcClient/OidcClient.cs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,18 @@ public class OidcClient
3636
/// <exception cref="System.ArgumentNullException">options</exception>
3737
public OidcClient(OidcClientOptions options)
3838
{
39-
if (options == null) throw new ArgumentNullException(nameof(options));
39+
if (options == null)
40+
{
41+
throw new ArgumentNullException(nameof(options));
42+
}
4043

4144
if (options.ProviderInformation == null)
4245
{
43-
if (options.Authority.IsMissing()) throw new ArgumentException("No authority specified", nameof(Options.Authority));
46+
if (options.Authority.IsMissing())
47+
{
48+
throw new ArgumentException("No authority specified", nameof(Options.Authority));
49+
}
50+
4451
_useDiscovery = true;
4552
}
4653

@@ -61,7 +68,10 @@ public virtual async Task<LoginResult> LoginAsync(LoginRequest request = null, C
6168
_logger.LogTrace("LoginAsync");
6269
_logger.LogInformation("Starting authentication request.");
6370

64-
if (request == null) request = new LoginRequest();
71+
if (request == null)
72+
{
73+
request = new LoginRequest();
74+
}
6575

6676
await EnsureConfigurationAsync(cancellationToken);
6777

@@ -132,7 +142,10 @@ public virtual async Task<string> PrepareLogoutAsync(LogoutRequest request = def
132142
/// <returns></returns>
133143
public virtual async Task<LogoutResult> LogoutAsync(LogoutRequest request = null, CancellationToken cancellationToken = default)
134144
{
135-
if (request == null) request = new LogoutRequest();
145+
if (request == null)
146+
{
147+
request = new LogoutRequest();
148+
}
136149

137150
await EnsureConfigurationAsync(cancellationToken);
138151

@@ -276,8 +289,15 @@ public virtual async Task<UserInfoResult> GetUserInfoAsync(string accessToken, C
276289
_logger.LogTrace("GetUserInfoAsync");
277290

278291
await EnsureConfigurationAsync(cancellationToken);
279-
if (accessToken.IsMissing()) throw new ArgumentNullException(nameof(accessToken));
280-
if (!Options.ProviderInformation.SupportsUserInfo) throw new InvalidOperationException("No userinfo endpoint specified");
292+
if (accessToken.IsMissing())
293+
{
294+
throw new ArgumentNullException(nameof(accessToken));
295+
}
296+
297+
if (!Options.ProviderInformation.SupportsUserInfo)
298+
{
299+
throw new InvalidOperationException("No userinfo endpoint specified");
300+
}
281301

282302
var userInfoClient = Options.CreateClient();
283303

identity-model-oidc-client/src/IdentityModel.OidcClient/RefreshTokenDelegatingHandler.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,17 @@ public RefreshTokenDelegatingHandler(OidcClient oidcClient, string accessToken,
9696

9797
_logger = _oidcClient.Options.LoggerFactory.CreateLogger<RefreshTokenDelegatingHandler>();
9898

99-
if (refreshToken.IsMissing()) throw new ArgumentNullException(nameof(refreshToken));
99+
if (refreshToken.IsMissing())
100+
{
101+
throw new ArgumentNullException(nameof(refreshToken));
102+
}
103+
100104
_refreshToken = refreshToken;
101105

102-
if (innerHandler != null) InnerHandler = innerHandler;
106+
if (innerHandler != null)
107+
{
108+
InnerHandler = innerHandler;
109+
}
103110
}
104111

105112
/// <summary>

identity-model-oidc-client/test/IdentityModel.OidcClient.Tests/DPoP/Framework/GenericHost.cs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ public class GenericHost : IAsyncDisposable
1515
{
1616
public GenericHost(string baseAddress = "https://server")
1717
{
18-
if (baseAddress.EndsWith("/")) baseAddress = baseAddress.Substring(0, baseAddress.Length - 1);
18+
if (baseAddress.EndsWith("/"))
19+
{
20+
baseAddress = baseAddress.Substring(0, baseAddress.Length - 1);
21+
}
22+
1923
_baseAddress = baseAddress;
2024
}
2125

@@ -37,7 +41,11 @@ public T Resolve<T>() where T : notnull =>
3741
public string Url(string path = null)
3842
{
3943
path = path ?? string.Empty;
40-
if (!path.StartsWith("/")) path = "/" + path;
44+
if (!path.StartsWith("/"))
45+
{
46+
path = "/" + path;
47+
}
48+
4149
return _baseAddress + path;
4250
}
4351

@@ -99,18 +107,33 @@ void ConfigureApp(IApplicationBuilder app)
99107

100108
public async ValueTask DisposeAsync()
101109
{
102-
if (Server != null) await CastAndDispose(Server);
103-
if (HttpClient != null) await CastAndDispose(HttpClient);
104-
if (Logger != null) await CastAndDispose(Logger);
110+
if (Server != null)
111+
{
112+
await CastAndDispose(Server);
113+
}
114+
115+
if (HttpClient != null)
116+
{
117+
await CastAndDispose(HttpClient);
118+
}
119+
120+
if (Logger != null)
121+
{
122+
await CastAndDispose(Logger);
123+
}
105124

106125
return;
107126

108127
static async ValueTask CastAndDispose(IDisposable resource)
109128
{
110129
if (resource is IAsyncDisposable resourceAsyncDisposable)
130+
{
111131
await resourceAsyncDisposable.DisposeAsync();
132+
}
112133
else
134+
{
113135
resource?.Dispose();
136+
}
114137
}
115138
}
116139
}

identity-model-oidc-client/test/IdentityModel.OidcClient.Tests/Infrastructure/NetworkHandler.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
6666
return _action(request);
6767
}
6868

69-
if (_behavior == Behavior.Throw) throw _exception;
69+
if (_behavior == Behavior.Throw)
70+
{
71+
throw _exception;
72+
}
7073

7174
var response = new HttpResponseMessage(_statusCode);
7275

@@ -92,7 +95,10 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
9295

9396
private async Task<string> SafeReadContentFrom(HttpRequestMessage request)
9497
{
95-
if (request.Content == null) return null;
98+
if (request.Content == null)
99+
{
100+
return null;
101+
}
96102

97103
return await request.Content.ReadAsStringAsync();
98104
}

identity-model-oidc-client/test/IdentityModel.OidcClient.Tests/RefreshTokenDelegatingHandlerTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ public async Task Can_refresh_access_tokens_in_parallel()
6161
async Task PerformPingRequests()
6262
{
6363
for (var i = 0; i < callsPerThread; i++)
64+
{
6465
await client.SecuredPing();
66+
}
6567
}
6668

6769
var tasks = Enumerable.Range(0, logicalThreadCount).Select(i => PerformPingRequests());
@@ -94,7 +96,9 @@ public async Task SecuredPing()
9496
var response = await _client.GetAsync("/whatever");
9597

9698
if (response.IsSuccessStatusCode)
99+
{
97100
return;
101+
}
98102
}
99103

100104
throw new Exception("The client was not able to recover.");
@@ -164,9 +168,13 @@ public bool IsValid(string accessToken)
164168
var expired = useCount > _maxCallsPerAccessToken;
165169

166170
if (expired)
171+
{
167172
_writeLine?.Invoke($"{accessToken} is no longer valid because it has been used {useCount} times (more than the {_maxCallsPerAccessToken} allowed)");
173+
}
168174
else
175+
{
169176
_writeLine?.Invoke($"{accessToken} is still valid (used {useCount} times now)");
177+
}
170178

171179
return !expired;
172180
}

0 commit comments

Comments
 (0)