Skip to content

Commit 3e14dd7

Browse files
Copilotmarcominerva
andcommitted
Remove EnableJwtBearerService setting and always register IJwtBearerService
Co-authored-by: marcominerva <3522534+marcominerva@users.noreply.github.com>
1 parent 66784b8 commit 3e14dd7

6 files changed

Lines changed: 6 additions & 19 deletions

File tree

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ Authentication can be totally configured adding an _Authentication_ section in t
4141
"Issuers": [ "issuer" ], // Optional
4242
"Audiences": [ "audience" ], // Optional
4343
"ExpirationTime": "01:00:00", // Default: No expiration
44-
"ClockSkew": "00:02:00", // Default: 5 minutes
45-
"EnableJwtBearerService": true // Default: true
44+
"ClockSkew": "00:02:00" // Default: 5 minutes
4645
},
4746
"ApiKey": {
4847
"SchemeName": "ApiKey", // Default: ApiKey
@@ -139,7 +138,7 @@ builder.Services.AddOpenApi(options =>
139138

140139
**Creating a JWT Bearer**
141140

142-
When using JWT Bearer authentication, you can set the _EnableJwtBearerService_ setting to _true_ to automatically register an implementation of the [IJwtBearerService](https://github.com/marcominerva/SimpleAuthentication/blob/master/src/SimpleAuthentication.Abstractions/JwtBearer/IJwtBearerService.cs) interface to create a valid JWT Bearer, according to the setting you have specified in the _appsettings.json_ file:
141+
When using JWT Bearer authentication, an implementation of the [IJwtBearerService](https://github.com/marcominerva/SimpleAuthentication/blob/master/src/SimpleAuthentication.Abstractions/JwtBearer/IJwtBearerService.cs) interface is automatically registered to create a valid JWT Bearer, according to the settings you have specified in the _appsettings.json_ file:
143142

144143
```csharp
145144
app.MapPost("api/auth/login", (LoginRequest loginRequest, IJwtBearerService jwtBearerService) =>

samples/Controllers/JwtBearerSample/appsettings.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
"Issuers": [ "issuer" ], // Optional
1111
"Audiences": [ "audience" ], // Optional
1212
"ExpirationTime": "01:00:00", // Default: No expiration
13-
"ClockSkew": "00:02:00", // Default: 5 minutes
14-
"EnableJwtBearerService": true // Default: true
13+
"ClockSkew": "00:02:00" // Default: 5 minutes
1514
}
1615
},
1716
"Logging": {

samples/MinimalApis/JwtBearerSample/appsettings.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
"Issuers": [ "issuer" ], // Optional
1111
"Audiences": [ "audience" ], // Optional
1212
"ExpirationTime": "01:00:00", // Default: No expiration
13-
"ClockSkew": "00:02:00", // Default: 5 minutes
14-
"EnableJwtBearerService": true // Default: true
13+
"ClockSkew": "00:02:00" // Default: 5 minutes
1514
}
1615
},
1716
"Logging": {

samples/MinimalApis/Net8JwtBearerSample/appsettings.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
"Issuers": [ "issuer" ], // Optional
1111
"Audiences": [ "audience" ], // Optional
1212
"ExpirationTime": "01:00:00", // Default: No expiration
13-
"ClockSkew": "00:02:00", // Default: 5 minutes
14-
"EnableJwtBearerService": true // Default: true
13+
"ClockSkew": "00:02:00" // Default: 5 minutes
1514
}
1615
},
1716
"Logging": {

src/SimpleAuthentication.Abstractions/JwtBearer/JwtBearerSettings.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,4 @@ public class JwtBearerSettings
6767
/// The default is <see cref="ClaimsIdentity.DefaultRoleClaimType"/>.
6868
/// </remarks>
6969
public string RoleClaimType { get; set; } = ClaimsIdentity.DefaultRoleClaimType;
70-
71-
/// <summary>
72-
/// <see langword="true"/> to register the <see cref="IJwtBearerService"/> service in the <see cref="IServiceCollection"/> (Default: true).
73-
/// </summary>
74-
/// <seealso cref="IJwtBearerService"/>
75-
public bool EnableJwtBearerService { get; set; } = true;
7670
}

src/SimpleAuthentication/SimpleAuthenticationExtensions.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,7 @@ static void CheckAddJwtBearer(AuthenticationBuilder builder, IConfigurationSecti
113113
};
114114
});
115115

116-
if (settings.EnableJwtBearerService)
117-
{
118-
builder.Services.TryAddSingleton<IJwtBearerService, JwtBearerService>();
119-
}
116+
builder.Services.TryAddSingleton<IJwtBearerService, JwtBearerService>();
120117
}
121118

122119
static void CheckAddApiKey(AuthenticationBuilder builder, IConfigurationSection section)

0 commit comments

Comments
 (0)