Skip to content

Commit

Permalink
Code updates for sample projects in description (#197)
Browse files Browse the repository at this point in the history
* Configuration, diagnostics, DPOP

* Code update for MTLS, PAT, ScopesAndResources, SessionManagement, TokenExchange

* Modernize code for AspNetIdentity and all BFF examples (#194)

* Modernize code for AspNetIdentity and all BFF examples

* Fixed log issues

* Fixed more log issues

* Added missing parenthesis

---------

Co-authored-by: Roland Guijt <[email protected]>

* Output accesstoken instead of JSON (#199)

Co-authored-by: Roland Guijt <[email protected]>

* Updates for UserInteraction (#198)

Co-authored-by: Roland Guijt <[email protected]>

* Update Angular CLI

* Update to Angular CLI v. 17

* Update to Angular v17 2

* Update to Angular 18

* BFF now requests offline_access, useEndpoints removed (#202)

* Request offline_access

* Remove limited access token lifetime

---------

Co-authored-by: Roland Guijt <[email protected]>

* Use DI for HttpClient
Use AccessTokenManagement to utilize refresh token
Add missing link in layout page

* Remove offline_access

* Remove parenthesis

* New qs: Token Management

* Add commented out code for "manual" mode

* Better name for token object

* tweaks to quickstart 1

* Update to IdentityServer 7.0.7

* Update Aspire to latest version

* Update OpenTelemetry.Instrumentation.GrpcNetClient

* Configuration, diagnostics, DPOP

* Code update for MTLS, PAT, ScopesAndResources, SessionManagement, TokenExchange

* Update to IdentityServer 7.0.7

---------

Co-authored-by: Roland Guijt <[email protected]>
Co-authored-by: Dominick Baier <[email protected]>
Co-authored-by: Joe DeCock <[email protected]>
Co-authored-by: Adam Ralph <[email protected]>
  • Loading branch information
5 people authored Sep 22, 2024
1 parent a97c84b commit 38ab386
Show file tree
Hide file tree
Showing 92 changed files with 1,008 additions and 1,735 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Duende.IdentityServer.Configuration" Version="7.0.0" />
<PackageReference Include="Duende.IdentityServer.Configuration.EntityFramework" Version="7.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.1" />
<PackageReference Include="Duende.IdentityServer.Configuration" Version="7.0.7" />
<PackageReference Include="Duende.IdentityServer.Configuration.EntityFramework" Version="7.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.6" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="IdentityModel" Version="7.0.0-preview.1" />
<PackageReference Include="IdentityModel" Version="7.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Diagnostics;

public static class ConsoleExtensions
Expand All @@ -13,16 +12,6 @@ public static void ConsoleGreen(this string text)
text.ColoredWriteLine(ConsoleColor.Green);
}

/// <summary>
/// Writes red text to the console.
/// </summary>
/// <param name="text">The text.</param>
[DebuggerStepThrough]
public static void ConsoleRed(this string text)
{
text.ColoredWriteLine(ConsoleColor.Red);
}

/// <summary>
/// Writes yellow text to the console.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Duende.IdentityServer.EntityFramework" Version="7.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="8.0.1" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.1" />
<PackageReference Include="Duende.IdentityServer.EntityFramework" Version="7.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="8.0.6" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System.Linq;

namespace SimpleApi.Controllers
namespace SimpleApi.Controllers;

[Route("identity")]
public class IdentityController : ControllerBase
{
[Route("identity")]
public class IdentityController : ControllerBase
{
private readonly ILogger<IdentityController> _logger;
private readonly ILogger<IdentityController> _logger;

public IdentityController(ILogger<IdentityController> logger)
{
_logger = logger;
}
public IdentityController(ILogger<IdentityController> logger)
{
_logger = logger;
}

[HttpGet]
public ActionResult Get()
{
var claims = User.Claims.Select(c => new { c.Type, c.Value });
_logger.LogInformation("claims: {claims}", claims);
[HttpGet]
public ActionResult Get()
{
var claims = User.Claims.Select(c => new { c.Type, c.Value });
_logger.LogInformation("claims: {claims}", claims);

return new JsonResult(claims);
}
return new JsonResult(claims);
}
}
72 changes: 38 additions & 34 deletions IdentityServer/v7/Configuration/Permissions/SimpleApi/Program.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,41 @@
using System;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Serilog;
using Serilog.Events;
using Serilog.Sinks.SystemConsole.Themes;
using Serilog;

namespace SimpleApi
{
public class Program
Console.Title = "API";

Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information()
.Enrich.FromLogContext()
.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}", theme: AnsiConsoleTheme.Code)
.CreateLogger();

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddSerilog();
builder.Services.AddControllers();

// this API will accept any access token from the authority
builder.Services.AddAuthentication("token")
.AddJwtBearer("token", options =>
{
public static void Main(string[] args)
{
Console.Title = "API";

BuildWebHost(args).Run();
}

public static IHost BuildWebHost(string[] args)
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information()
.Enrich.FromLogContext()
.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}", theme: AnsiConsoleTheme.Code)
.CreateLogger();

return Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
})
.UseSerilog()
.Build();
}
}
}
options.Authority = "https://localhost:5001";
options.MapInboundClaims = false;

options.TokenValidationParameters.ValidateAudience = false;
options.TokenValidationParameters.ValidTypes = new[] { "at+jwt" };
});

builder.Services.AddAuthorization(options =>
{
options.AddPolicy("SimpleApi", p => p.RequireClaim("scope", "SimpleApi"));
});

var app = builder.Build();

app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();

app.MapControllers().RequireAuthorization();

app.Run();
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.1" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.6" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
</ItemGroup>

</Project>
42 changes: 0 additions & 42 deletions IdentityServer/v7/Configuration/Permissions/SimpleApi/Startup.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Duende.IdentityServer.Configuration" Version="7.0.0" />
<PackageReference Include="Duende.IdentityServer.Configuration.EntityFramework" Version="7.0.0" />
<PackageReference Include="Duende.IdentityServer.Configuration" Version="7.0.7" />
<PackageReference Include="Duende.IdentityServer.Configuration.EntityFramework" Version="7.0.7" />
<PackageReference Include="IdentityModel.AspNetCore.OAuth2Introspection" Version="6.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.6" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="IdentityModel" Version="6.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
<PackageReference Include="IdentityModel" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Duende.IdentityServer.EntityFramework" Version="7.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="8.0.1" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.1" />
<PackageReference Include="Duende.IdentityServer.EntityFramework" Version="7.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="8.0.6" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System.Linq;

namespace SimpleApi.Controllers
namespace SimpleApi.Controllers;

[Route("identity")]
public class IdentityController : ControllerBase
{
[Route("identity")]
public class IdentityController : ControllerBase
{
private readonly ILogger<IdentityController> _logger;
private readonly ILogger<IdentityController> _logger;

public IdentityController(ILogger<IdentityController> logger)
{
_logger = logger;
}
public IdentityController(ILogger<IdentityController> logger)
{
_logger = logger;
}

[HttpGet]
public ActionResult Get()
{
var claims = User.Claims.Select(c => new { c.Type, c.Value });
_logger.LogInformation("claims: {claims}", claims);
[HttpGet]
public ActionResult Get()
{
var claims = User.Claims.Select(c => new { c.Type, c.Value });
_logger.LogInformation("claims: {claims}", claims);

return new JsonResult(claims);
}
return new JsonResult(claims);
}
}
Loading

0 comments on commit 38ab386

Please sign in to comment.