Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions samples/Controllers/ApiKeySample/ApiKeySample.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.3" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.8" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="9.0.4" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\SimpleAuthentication.Swashbuckle\SimpleAuthentication.Swashbuckle.csproj" />
<ProjectReference Include="..\..\..\src\SimpleAuthentication\SimpleAuthentication.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\SimpleAuthentication.Swashbuckle\SimpleAuthentication.Swashbuckle.csproj" />
<ProjectReference Include="..\..\..\src\SimpleAuthentication\SimpleAuthentication.csproj" />
</ItemGroup>

</Project>
20 changes: 7 additions & 13 deletions samples/Controllers/ApiKeySample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@

builder.Services.AddTransient<IClaimsTransformation, ClaimsTransformer>();

// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();

builder.Services.AddSwaggerGen(options =>
builder.Services.AddOpenApi(options =>
{
options.AddSimpleAuthentication(builder.Configuration);
});
Expand All @@ -45,18 +42,15 @@
// Configure the HTTP request pipeline.
app.UseHttpsRedirection();

if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler();
}

app.UseExceptionHandler();
app.UseStatusCodePages();

if (app.Environment.IsDevelopment())
app.MapOpenApi();

app.UseSwaggerUI(options =>
{
app.UseSwagger();
app.UseSwaggerUI();
}
options.SwaggerEndpoint("/openapi/v1.json", app.Environment.ApplicationName);
});

app.UseAuthentication();
app.UseAuthorization();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.3" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.8" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="9.0.4" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\SimpleAuthentication.Swashbuckle\SimpleAuthentication.Swashbuckle.csproj" />
<ProjectReference Include="..\..\..\src\SimpleAuthentication\SimpleAuthentication.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\SimpleAuthentication.Swashbuckle\SimpleAuthentication.Swashbuckle.csproj" />
<ProjectReference Include="..\..\..\src\SimpleAuthentication\SimpleAuthentication.csproj" />
</ItemGroup>

</Project>
20 changes: 7 additions & 13 deletions samples/Controllers/BasicAuthenticationSample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@

builder.Services.AddTransient<IClaimsTransformation, ClaimsTransformer>();

// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();

builder.Services.AddSwaggerGen(options =>
builder.Services.AddOpenApi(options =>
{
options.AddSimpleAuthentication(builder.Configuration);
});
Expand All @@ -46,18 +43,15 @@
// Configure the HTTP request pipeline.
app.UseHttpsRedirection();

if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler();
}

app.UseExceptionHandler();
app.UseStatusCodePages();

if (app.Environment.IsDevelopment())
app.MapOpenApi();

app.UseSwaggerUI(options =>
{
app.UseSwagger();
app.UseSwaggerUI();
}
options.SwaggerEndpoint("/openapi/v1.json", app.Environment.ApplicationName);
});

app.UseAuthentication();
app.UseAuthorization();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Security.Claims;
using Microsoft.AspNetCore.Mvc;
using SimpleAuthentication.JwtBearer;
using Swashbuckle.AspNetCore.Annotations;

namespace JwtBearerSample.Controllers;

Expand All @@ -14,7 +13,7 @@ public class AuthController(IJwtBearerService jwtBearerService) : ControllerBase
[HttpPost("login")]
[ProducesResponseType<LoginResponse>(StatusCodes.Status200OK)]
[ProducesDefaultResponseType]
[SwaggerOperation(description: "Insert permissions in the scope property (for example: 'profile people:admin')")]
[EndpointDescription(description: "Insert permissions in the scope property (for example: 'profile people:admin')")]
public async Task<ActionResult<LoginResponse>> Login(LoginRequest loginRequest, DateTime? expiration = null)
{
// Check for login rights...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SimpleAuthentication.Permissions;
using Swashbuckle.AspNetCore.Annotations;

namespace JwtBearerSample.Controllers;

Expand All @@ -16,7 +15,7 @@ public class MeController : ControllerBase
[HttpGet]
[ProducesResponseType<User>(StatusCodes.Status200OK)]
[ProducesDefaultResponseType]
[SwaggerOperation(description: "This endpoint requires the 'profile' permission")]
[EndpointDescription(description: "This endpoint requires the 'profile' permission")]
public ActionResult<User> Get()
=> new User(User.Identity!.Name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SimpleAuthentication.Permissions;
using Swashbuckle.AspNetCore.Annotations;

namespace JwtBearerSample.Controllers;

Expand All @@ -14,35 +13,35 @@ public class PeopleController : ControllerBase
{
[Authorize(Policy = "PeopleRead")] // [Permissions(Permissions.PeopleRead, Permissions.PeopleAdmin)]
[HttpGet]
[SwaggerOperation(description: $"This endpoint requires the '{Permissions.PeopleRead}' or '{Permissions.PeopleAdmin}' permissions")]
[EndpointDescription(description: $"This endpoint requires the '{Permissions.PeopleRead}' or '{Permissions.PeopleAdmin}' permissions")]
public IActionResult GetList() => NoContent();

[Authorize(Policy = "PeopleRead")] // [Permissions(Permissions.PeopleRead, Permissions.PeopleAdmin)]
[HttpGet("{id:int}")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesDefaultResponseType]
[SwaggerOperation(description: $"This endpoint requires the '{Permissions.PeopleRead}' or '{Permissions.PeopleAdmin}' permissions")]
[EndpointDescription(description: $"This endpoint requires the '{Permissions.PeopleRead}' or '{Permissions.PeopleAdmin}' permissions")]
public IActionResult GetPerson(int id) => NoContent();

[Permission(Permissions.PeopleWrite)]
[HttpPost]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesDefaultResponseType]
[SwaggerOperation(description: $"This endpoint requires the '{Permissions.PeopleWrite}' permission")]
[EndpointDescription(description: $"This endpoint requires the '{Permissions.PeopleWrite}' permission")]
public IActionResult Insert() => NoContent();

[Permission(Permissions.PeopleWrite)]
[HttpPut]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesDefaultResponseType]
[SwaggerOperation(description: $"This endpoint requires the '{Permissions.PeopleWrite}' permission")]
[EndpointDescription(description: $"This endpoint requires the '{Permissions.PeopleWrite}' permission")]
public IActionResult Update() => NoContent();

[Permission(Permissions.PeopleAdmin)]
[HttpDelete("{id:int}")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesDefaultResponseType]
[SwaggerOperation(description: $"This endpoint requires the '{Permissions.PeopleAdmin}' permission")]
[EndpointDescription(description: $"This endpoint requires the '{Permissions.PeopleAdmin}' permission")]
public IActionResult Delete(int id) => NoContent();
}

Expand Down
4 changes: 2 additions & 2 deletions samples/Controllers/JwtBearerSample/JwtBearerSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="9.0.3" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.8" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="9.0.4" />
</ItemGroup>

<ItemGroup>
Expand Down
21 changes: 7 additions & 14 deletions samples/Controllers/JwtBearerSample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,8 @@

builder.Services.AddTransient<IClaimsTransformation, ClaimsTransformer>();

// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();

builder.Services.AddSwaggerGen(options =>
builder.Services.AddOpenApi(options =>
{
options.EnableAnnotations();
options.AddSimpleAuthentication(builder.Configuration);
});

Expand All @@ -55,18 +51,15 @@
// Configure the HTTP request pipeline.
app.UseHttpsRedirection();

if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler();
}

app.UseExceptionHandler();
app.UseStatusCodePages();

if (app.Environment.IsDevelopment())
app.MapOpenApi();

app.UseSwaggerUI(options =>
{
app.UseSwagger();
app.UseSwaggerUI();
}
options.SwaggerEndpoint("/openapi/v1.json", app.Environment.ApplicationName);
});

app.UseAuthentication();
app.UseAuthorization();
Expand Down
4 changes: 2 additions & 2 deletions samples/MinimalApis/ApiKeySample/ApiKeySample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.7" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.3" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.8" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="9.0.4" />
</ItemGroup>

<ItemGroup>
Expand Down
20 changes: 7 additions & 13 deletions samples/MinimalApis/ApiKeySample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@

builder.Services.AddTransient<IClaimsTransformation, ClaimsTransformer>();

// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();

builder.Services.AddSwaggerGen(options =>
builder.Services.AddOpenApi(options =>
{
options.AddSimpleAuthentication(builder.Configuration);
});
Expand All @@ -45,18 +42,15 @@
// Configure the HTTP request pipeline.
app.UseHttpsRedirection();

if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler();
}

app.UseExceptionHandler();
app.UseStatusCodePages();

if (app.Environment.IsDevelopment())
app.MapOpenApi();

app.UseSwaggerUI(options =>
{
app.UseSwagger();
app.UseSwaggerUI();
}
options.SwaggerEndpoint("/openapi/v1.json", app.Environment.ApplicationName);
});

app.UseAuthentication();
app.UseAuthorization();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.7" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.3" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.8" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="9.0.4" />
</ItemGroup>

<ItemGroup>
Expand Down
20 changes: 7 additions & 13 deletions samples/MinimalApis/BasicAuthenticationSample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@

builder.Services.AddTransient<IClaimsTransformation, ClaimsTransformer>();

// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();

builder.Services.AddSwaggerGen(options =>
builder.Services.AddOpenApi(options =>
{
options.AddSimpleAuthentication(builder.Configuration);
});
Expand All @@ -45,18 +42,15 @@
// Configure the HTTP request pipeline.
app.UseHttpsRedirection();

if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler();
}

app.UseExceptionHandler();
app.UseStatusCodePages();

if (app.Environment.IsDevelopment())
app.MapOpenApi();

app.UseSwaggerUI(options =>
{
app.UseSwagger();
app.UseSwaggerUI();
}
options.SwaggerEndpoint("/openapi/v1.json", app.Environment.ApplicationName);
});

app.UseAuthentication();
app.UseAuthorization();
Expand Down
4 changes: 2 additions & 2 deletions samples/MinimalApis/JwtBearerSample/JwtBearerSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.7" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="9.0.3" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.8" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="9.0.4" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading
Loading