Skip to content

Commit 49a281e

Browse files
committed
Update JWT version, OpenAPI docs, and code style settings
- Set dotnet_style_require_accessibility_modifiers in .editorconfig - Remove Microsoft.AspNetCore.OpenApi from Net8JwtBearerSample.csproj - Bump JwtBearer package to 10.0.1 for net10.0 - Add bearerFormat ("JWT") to OpenAPI security scheme - Rename errorSchema to problemDetailsSchema for clarity
1 parent 8e27da5 commit 49a281e

File tree

5 files changed

+7
-9
lines changed

5 files changed

+7
-9
lines changed

.editorconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ csharp_style_prefer_local_over_anonymous_function = true:silent
8282
csharp_style_prefer_extended_property_pattern = true:suggestion
8383
csharp_style_implicit_object_creation_when_type_is_apparent = true:silent
8484
csharp_style_prefer_tuple_swap = true:silent
85-
csharp_style_prefer_simple_property_accessors = true:suggestion
8685

8786
# Field preferences
8887
dotnet_style_readonly_field = true:suggestion

samples/MinimalApis/Net8JwtBearerSample/Net8JwtBearerSample.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="[8.0.22,9.0.0)" />
1110
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.0.1" />
1211
</ItemGroup>
1312

src/SimpleAuthentication.Abstractions/SimpleAuthentication.Abstractions.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
</ItemGroup>
3737

3838
<ItemGroup Condition="'$(TargetFramework)' == 'net10.0'">
39-
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.0" />
39+
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.1" />
4040
</ItemGroup>
4141

4242
<ItemGroup>

src/SimpleAuthentication/OpenApi/AuthenticationDocumentTransformer.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ static void CheckAddJwtBearer(OpenApiDocument document, IConfigurationSection se
157157
return;
158158
}
159159

160-
AddSecurityScheme(document, settings.SchemeName, SecuritySchemeType.Http, JwtBearerDefaults.AuthenticationScheme, ParameterLocation.Header, HeaderNames.Authorization, "Insert the Bearer Token");
160+
AddSecurityScheme(document, settings.SchemeName, SecuritySchemeType.Http, JwtBearerDefaults.AuthenticationScheme, ParameterLocation.Header, HeaderNames.Authorization, "Insert the Bearer Token", "JWT");
161161
AddSecurityRequirement(document, settings.SchemeName);
162162
}
163163

@@ -199,7 +199,7 @@ static void CheckAddBasicAuthentication(OpenApiDocument document, IConfiguration
199199
}
200200
}
201201

202-
private static void AddSecurityScheme(OpenApiDocument document, string name, SecuritySchemeType securitySchemeType, string? scheme, ParameterLocation location, string parameterName, string description)
202+
private static void AddSecurityScheme(OpenApiDocument document, string name, SecuritySchemeType securitySchemeType, string? scheme, ParameterLocation location, string parameterName, string description, string? bearerFormat = null)
203203
{
204204
document.Components ??= new();
205205
document.Components.SecuritySchemes ??= new Dictionary<string, IOpenApiSecurityScheme>();
@@ -210,7 +210,8 @@ private static void AddSecurityScheme(OpenApiDocument document, string name, Sec
210210
Name = parameterName,
211211
Description = description,
212212
Type = securitySchemeType,
213-
Scheme = scheme
213+
Scheme = scheme,
214+
BearerFormat = bearerFormat
214215
});
215216
}
216217

src/SimpleAuthentication/OpenApi/DefaultResponseDocumentTransformer.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ public Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransformerC
6262

6363
#elif NET10_0_OR_GREATER
6464

65-
using System.Net.Mime;
6665
using Microsoft.AspNetCore.Mvc;
6766
using Microsoft.AspNetCore.OpenApi;
6867
using Microsoft.OpenApi;
@@ -74,8 +73,8 @@ internal class DefaultResponseDocumentTransformer : IOpenApiDocumentTransformer
7473
public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransformerContext context, CancellationToken cancellationToken)
7574
{
7675
// Generate schema for error responses.
77-
var errorSchema = await context.GetOrCreateSchemaAsync(typeof(ProblemDetails), cancellationToken: cancellationToken);
78-
document.AddComponent(nameof(ProblemDetails), errorSchema);
76+
var problemDetailsSchema = await context.GetOrCreateSchemaAsync(typeof(ProblemDetails), cancellationToken: cancellationToken);
77+
document.AddComponent(nameof(ProblemDetails), problemDetailsSchema);
7978
}
8079
}
8180

0 commit comments

Comments
 (0)