Skip to content

Commit ded3efb

Browse files
committed
Update packages, enhance JWT options, and refactor configs
Updated Roslynator.Analyzers to 4.12.9 and Scrutor to 5.0.1. Enhanced JwtOptions with XML docs and new default values. Refactored RabbitMQ config in ServiceCollectionExtensions. Added JWT settings to appsettings.json and disabled azureKeyVault. Updated various Microsoft.Extensions packages in Genocs.Core.csproj. Tested to use auth with simmetric key.
1 parent 318ca61 commit ded3efb

File tree

7 files changed

+56
-15
lines changed

7 files changed

+56
-15
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</PropertyGroup>
1414

1515
<ItemGroup>
16-
<PackageReference Include="Roslynator.Analyzers" Version="4.12.4">
16+
<PackageReference Include="Roslynator.Analyzers" Version="4.12.9">
1717
<PrivateAssets>all</PrivateAssets>
1818
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1919
</PackageReference>

src/Genocs.Auth/Configurations/JwtOptions.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,41 @@ public class JwtOptions
3838
public string? ValidIssuer { get; set; }
3939
public IEnumerable<string>? ValidIssuers { get; set; }
4040
public bool ValidateActor { get; set; }
41+
42+
/// <summary>
43+
/// It defines whether the audience should be validated.
44+
/// Defaults to true.
45+
/// </summary>
4146
public bool ValidateAudience { get; set; } = true;
47+
48+
/// <summary>
49+
/// It defines whether the issuer should be validated.
50+
/// Defaults to true.
51+
/// </summary>
4252
public bool ValidateIssuer { get; set; } = true;
4353
public bool ValidateLifetime { get; set; } = true;
4454
public bool ValidateTokenReplay { get; set; }
4555
public bool ValidateIssuerSigningKey { get; set; }
56+
57+
/// <summary>
58+
/// It defines whether the token should be refreshed when the issuer key is not found.
59+
/// Defaults to true.
60+
/// </summary>
4661
public bool RefreshOnIssuerKeyNotFound { get; set; } = true;
62+
63+
/// <summary>
64+
/// It defines whether the error details should be included in the response.
65+
/// Defaults to true.
66+
/// </summary>
4767
public bool IncludeErrorDetails { get; set; } = true;
4868
public string? AuthenticationType { get; set; }
4969
public string? NameClaimType { get; set; }
50-
public string? RoleClaimType { get; set; }
70+
71+
/// <summary>
72+
/// The claim type that will be used to determine the user's roles.
73+
/// Defaults to "Role".
74+
/// </summary>
75+
public string RoleClaimType { get; set; } = "Role";
5176

5277
public class CertificateOptions
5378
{

src/Genocs.Auth/Extensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ private static IGenocsBuilder AddJwt(
7070
SaveSigninToken = options.SaveSigninToken,
7171
RequireExpirationTime = options.RequireExpirationTime,
7272
RequireSignedTokens = options.RequireSignedTokens,
73+
RoleClaimType = options.RoleClaimType,
7374
ClockSkew = TimeSpan.Zero
7475
};
7576

@@ -117,6 +118,7 @@ private static IGenocsBuilder AddJwt(
117118
}
118119
}
119120

121+
// If no certificate is provided, use symmetric encryption.
120122
if (!string.IsNullOrWhiteSpace(options.IssuerSigningKey) && !hasCertificate)
121123
{
122124
if (string.IsNullOrWhiteSpace(options.Algorithm) || hasCertificate)

src/Genocs.Core.Demo.WebApi/Infrastructure/Extensions/ServiceCollectionExtensions.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,16 @@ public static IServiceCollection AddCustomMassTransit(this IServiceCollection se
6565
x.UsingRabbitMq((context, cfg) =>
6666
{
6767
cfg.ConfigureEndpoints(context);
68-
//cfg.UseHealthCheck(context);
69-
cfg.Host(rabbitMQSettings.HostName, rabbitMQSettings.VirtualHost,
70-
h =>
71-
{
72-
h.Username(rabbitMQSettings.UserName);
73-
h.Password(rabbitMQSettings.Password);
74-
}
75-
);
68+
69+
// cfg.UseHealthCheck(context);
70+
cfg.Host(
71+
rabbitMQSettings.HostName,
72+
rabbitMQSettings.VirtualHost,
73+
h =>
74+
{
75+
h.Username(rabbitMQSettings.UserName);
76+
h.Password(rabbitMQSettings.Password);
77+
});
7678
});
7779
});
7880

src/Genocs.Core.Demo.WebApi/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Genocs.Tracing;
99
using Microsoft.Extensions.Diagnostics.HealthChecks;
1010
using Serilog;
11+
using Genocs.Auth;
1112
using System.Reflection;
1213
using System.Text.Json.Serialization;
1314

@@ -23,6 +24,7 @@
2324

2425
services
2526
.AddGenocs(builder.Configuration)
27+
.AddJwt()
2628
// .AddOpenIdJwt()
2729
.AddOpenTelemetry()
2830
.AddMongoFast()

src/Genocs.Core.Demo.WebApi/appsettings.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@
3232
"ValidAudience": "https://localhost:5000",
3333
"Secret": ""
3434
},
35+
"_simmetric_jwt": {
36+
"issuerSigningKey": "This is my custom Secret key for authentication S0M3RAN0MS3CR3T!1!MAG1C!1!",
37+
"requireHttpsMetadata": false,
38+
"saveToken": true,
39+
"validateIssuerSigningKey": true,
40+
"validateIssuer": false,
41+
"validateLifetime": true,
42+
"validateAudience": false,
43+
"roleClaimType": "Role"
44+
},
3545
"rabbitMQ": {
3646
"HostName": "localhost",
3747
"VirtualHost": "/",
@@ -53,7 +63,7 @@
5363
"enableTracing": true
5464
},
5565
"azureKeyVault": {
56-
"enabled": true,
66+
"enabled": false,
5767
"name": "kv-genocs"
5868
},
5969
"secrets": {

src/Genocs.Core/Genocs.Core.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151

5252
<ItemGroup>
5353
<PackageReference Include="Figgle" Version="0.5.1" />
54-
<PackageReference Include="Scrutor" Version="4.2.2" />
54+
<PackageReference Include="Scrutor" Version="5.0.1" />
5555
</ItemGroup>
5656

5757
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
@@ -68,11 +68,11 @@
6868

6969
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
7070
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
71-
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.0" />
71+
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.1" />
7272
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
7373
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
74-
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
74+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
7575
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
76-
<PackageReference Include="System.Text.Json" Version="8.0.4" />
76+
<PackageReference Include="System.Text.Json" Version="8.0.5" />
7777
</ItemGroup>
7878
</Project>

0 commit comments

Comments
 (0)