Skip to content

Commit 0cd22eb

Browse files
authored
Merge pull request #168 from marcominerva/copilot/remove-jwt-bearer-setting
Remove EnableJwtBearerService setting and always register IJwtBearerService
2 parents e9accf0 + 1cfb988 commit 0cd22eb

6 files changed

Lines changed: 7 additions & 19 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Simple Authentication for ASP.NET Core
22

33
[![Lint Code Base](https://github.com/marcominerva/SimpleAuthentication/actions/workflows/linter.yml/badge.svg)](https://github.com/marcominerva/SimpleAuthentication/actions/workflows/linter.yml)
4-
[![CodeQL](https://github.com/marcominerva/SimpleAuthentication/actions/workflows/codeql.yml/badge.svg)](https://github.com/marcominerva/SimpleAuthentication/actions/workflows/codeql.yml)
4+
[![CodeQL](https://github.com/marcominerva/SimpleAuthentication/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/marcominerva/SimpleAuthentication/actions/workflows/github-code-scanning/codeql)
55
[![Nuget](https://img.shields.io/nuget/v/SimpleAuthenticationTools)](https://www.nuget.org/packages/SimpleAuthenticationTools)
66
[![Nuget](https://img.shields.io/nuget/dt/SimpleAuthenticationTools)](https://www.nuget.org/packages/SimpleAuthenticationTools)
77
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/marcominerva/SimpleAuthentication/blob/master/LICENSE)
@@ -138,7 +138,7 @@ builder.Services.AddOpenApi(options =>
138138

139139
**Creating a JWT Bearer**
140140

141-
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:
142142

143143
```csharp
144144
app.MapPost("api/auth/login", async (LoginRequest loginRequest, IJwtBearerService jwtBearerService) =>
@@ -316,4 +316,4 @@ app.MapGet("api/me", (ClaimsPrincipal user) =>
316316

317317
## Contribute
318318

319-
The project is constantly evolving. Contributions are welcome. Feel free to file issues and pull requests in the repository, and we'll address them as we can.
319+
The project is constantly evolving. Contributions are welcome. Feel free to file issues and pull requests in the repository, and we'll address them as we can.

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)