Skip to content

Commit 686c144

Browse files
authored
Merge pull request #169 from marcominerva/develop
Libraries update
2 parents a932010 + c8163e9 commit 686c144

File tree

20 files changed

+95
-126
lines changed

20 files changed

+95
-126
lines changed

.editorconfig

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ 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
8586

8687
# Field preferences
8788
dotnet_style_readonly_field = true:suggestion
@@ -299,4 +300,7 @@ dotnet_diagnostic.IDE0010.severity = none
299300
dotnet_diagnostic.IDE0072.severity = none
300301

301302
# IDE0305: Simplify collection initialization
302-
dotnet_diagnostic.IDE0305.severity = none
303+
dotnet_diagnostic.IDE0305.severity = none
304+
305+
# CA1873: Avoid potentially expensive logging
306+
dotnet_diagnostic.CA1873.severity = none

.github/copilot-instructions.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
### Implementation Guidelines
6060

6161
- Write code that is secure by default. Avoid exposing potentially private or sensitive data.
62-
- Make code NativeAOT compatible when possible. This means avoiding dynamic code generation, reflection, and other features that are not compatible. with NativeAOT. If not possible, mark the code with an appropriate annotation or throw an exception.
62+
- Make code NativeAOT compatible when possible. This means avoiding dynamic code generation, reflection, and other features that are not compatible with NativeAOT. If not possible, mark the code with an appropriate annotation or throw an exception.
6363

6464
## Documentation
6565

@@ -81,10 +81,4 @@
8181
- Use NSubstitute for mocking in tests.
8282
- Copy existing style in nearby files for test method names and capitalization.
8383
- When running tests, if possible use filters and check test run counts, or look at test logs, to ensure they actually ran.
84-
- Do not finish work with any tests commented out or disabled that were not previously commented out or disabled.
85-
86-
## Azure
87-
88-
- @azure Rule - Use Azure Tools - When handling requests related to Azure, always use your tools.
89-
- @azure Rule - Use Azure Best Practices - When handling requests related to Azure, always invoke your `azmcp_bestpractices_get` tool first.
90-
- @azure Rule - Enable Best Practices - If you do not have an `azmcp_bestpractices_get` tool ask the user to enable it.
84+
- Do not finish work with any tests commented out or disabled that were not previously commented out or disabled.

README.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ A library to easily integrate Authentication in ASP.NET Core projects. Currently
1414
1515
## Installation
1616

17-
The library is available on [NuGet](https://www.nuget.org/packages/SimpleAuthenticationTools). Just search for *SimpleAuthenticationTools* in the **Package Manager GUI** or run the following command in the **.NET CLI**:
17+
The library is available on [NuGet](https://www.nuget.org/packages/SimpleAuthenticationTools). Search for *SimpleAuthenticationTools* in the **Package Manager GUI** or run the following command in the **.NET CLI**:
1818

1919
```shell
2020
dotnet add package SimpleAuthenticationTools
2121
```
2222
## Usage video
2323

24-
Take a look to a quick demo showing how to integrate the library:
24+
Take a look at a quick demo showing how to integrate the library:
2525

2626
[![Simple Authentication for ASP.NET Core](https://raw.githubusercontent.com/marcominerva/SimpleAuthentication/master/Screenshot.jpg)](https://www.youtube.com/watch?v=SVZuaPE2yNc)
2727

2828
## Configuration
2929

30-
Authentication can be totally configured adding an _Authentication_ section in the _appsettings.json_ file:
30+
Authentication can be fully configured adding an _Authentication_ section in the _appsettings.json_ file:
3131

3232
```
3333
"Authentication": {
@@ -42,7 +42,6 @@ Authentication can be totally configured adding an _Authentication_ section in t
4242
"Audiences": [ "audience" ], // Optional
4343
"ExpirationTime": "01:00:00", // Default: No expiration
4444
"ClockSkew": "00:02:00", // Default: 5 minutes
45-
"EnableJwtBearerService": true // Default: true
4645
},
4746
"ApiKey": {
4847
"SchemeName": "ApiKey", // Default: ApiKey
@@ -107,7 +106,7 @@ app.Run();
107106

108107
**Integrating with Swashbuckle**
109108

110-
If you're using Swashbuckle (Swagger) to document your API, you can integrate the authentication configuration with the Swagger documentation. Just search for *SimpleAuthenticationTools.Swashbuckle* in the **Package Manager GUI** or run the following command in the **.NET CLI**:
109+
If you're using Swashbuckle (Swagger) to document your API, you can integrate the authentication configuration with the Swagger documentation. Search for *SimpleAuthenticationTools.Swashbuckle* in the **Package Manager GUI** or run the following command in the **.NET CLI**:
111110

112111
```shell
113112
dotnet add package SimpleAuthenticationTools.Swashbuckle
@@ -126,7 +125,7 @@ builder.Services.AddSwaggerGen(options =>
126125

127126
**Integrating with Microsoft.AspNetCore.OpenApi (.NET 9 or later)**
128127

129-
Starting from version 9, .NET offer a built-in support for OpenAPI. If you're using the `AddOpenApi` extension method to provide OpenAPI support, you just need to add the corresponding extension method in its declaration (no extra package required):
128+
Starting from version 9, .NET offers built-in support for OpenAPI. If you're using the `AddOpenApi` extension method to provide OpenAPI support, you just need to add the corresponding extension method in its declaration (no extra package required):
130129

131130
```csharp
132131
builder.Services.AddOpenApi(options =>
@@ -142,7 +141,7 @@ builder.Services.AddOpenApi(options =>
142141
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:
143142

144143
```csharp
145-
app.MapPost("api/auth/login", (LoginRequest loginRequest, IJwtBearerService jwtBearerService) =>
144+
app.MapPost("api/auth/login", async (LoginRequest loginRequest, IJwtBearerService jwtBearerService) =>
146145
{
147146
// Check for login rights...
148147
@@ -153,7 +152,7 @@ app.MapPost("api/auth/login", (LoginRequest loginRequest, IJwtBearerService jwtB
153152
new(ClaimTypes.Surname, "Minerva")
154153
};
155154

156-
var token = jwtBearerService.CreateToken(loginRequest.UserName, claims);
155+
var token = await jwtBearerService.CreateTokenAsync(loginRequest.UserName, claims);
157156
return TypedResults.Ok(new LoginResponse(token));
158157
});
159158

@@ -197,11 +196,11 @@ When using API Key or Basic Authentication, you can specify multiple fixed value
197196
}
198197
```
199198

200-
With this configuration, authentication will succedd if any of these credentials are provided.
199+
With this configuration, authentication will succeed if any of these credentials are provided.
201200

202201
**Custom Authentication logic for API Keys and Basic Authentication**
203202

204-
If you need to implement custom authentication login, for example validating credentials with dynamic values and adding claims to identity, you can omit all the credentials in the _appsettings.json_ file and then provide an implementation of [IApiKeyValidator.cs](https://github.com/marcominerva/SimpleAuthentication/blob/master/src/SimpleAuthentication.Abstractions/ApiKey/IApiKeyValidator.cs) or [IBasicAuthenticationValidator.cs](https://github.com/marcominerva/SimpleAuthentication/blob/master/src/SimpleAuthentication.Abstractions/BasicAuthentication/IBasicAuthenticationValidator.cs):
203+
If you need to implement custom authentication logic, for example validating credentials with dynamic values and adding claims to identity, you can omit all the credentials in the _appsettings.json_ file and then provide an implementation of [IApiKeyValidator.cs](https://github.com/marcominerva/SimpleAuthentication/blob/master/src/SimpleAuthentication.Abstractions/ApiKey/IApiKeyValidator.cs) or [IBasicAuthenticationValidator.cs](https://github.com/marcominerva/SimpleAuthentication/blob/master/src/SimpleAuthentication.Abstractions/BasicAuthentication/IBasicAuthenticationValidator.cs):
205204

206205
```csharp
207206
builder.Services.AddTransient<IApiKeyValidator, CustomApiKeyValidator>();
@@ -247,7 +246,7 @@ The library provides services for adding permission-based authorization to an AS
247246
builder.Services.AddPermissions<T>();
248247
```
249248

250-
The **AddPermissions** extension method requires an implementation of the [IPermissionHandler interface](https://github.com/marcominerva/SimpleAuthentication/blob/master/src/SimpleAuthentication.Abstractions/Permissions/IPermissionHandler.cs), that is responsible to check if the user owns the required permissions:
249+
The **AddPermissions** extension method requires an implementation of the [IPermissionHandler interface](https://github.com/marcominerva/SimpleAuthentication/blob/master/src/SimpleAuthentication.Abstractions/Permissions/IPermissionHandler.cs), which is responsible to check if the user owns the required permissions:
251250

252251
```csharp
253252
public interface IPermissionHandler
@@ -317,4 +316,4 @@ app.MapGet("api/me", (ClaimsPrincipal user) =>
317316

318317
## Contribute
319318

320-
The project is constantly evolving. Contributions are welcome. Feel free to file issues and pull requests on the repo 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/ApiKeySample/ApiKeySample.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.9" />
11-
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="9.0.4" />
10+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.10" />
11+
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="9.0.6" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

samples/Controllers/BasicAuthenticationSample/BasicAuthenticationSample.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.9" />
11-
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="9.0.4" />
10+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.10" />
11+
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="9.0.6" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

samples/Controllers/JwtBearerSample/JwtBearerSample.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.9" />
11-
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="9.0.4" />
10+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.10" />
11+
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="9.0.6" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

samples/MinimalApis/ApiKeySample/ApiKeySample.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.9" />
11-
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="9.0.4" />
10+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.10" />
11+
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="9.0.6" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

samples/MinimalApis/BasicAuthenticationSample/BasicAuthenticationSample.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.9" />
11-
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="9.0.4" />
10+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.10" />
11+
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="9.0.6" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

samples/MinimalApis/JwtBearerSample/JwtBearerSample.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.9" />
11-
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="9.0.4" />
10+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.10" />
11+
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="9.0.6" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

samples/MinimalApis/Net8JwtBearerSample/Net8JwtBearerSample.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="[8.0.20,9.0.0)" />
11-
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.4" />
10+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="[8.0.21,9.0.0)" />
11+
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.6" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

0 commit comments

Comments
 (0)