From 7e28899b710b3d6c5f820456dfaeb98e9be39166 Mon Sep 17 00:00:00 2001 From: github-actions Date: Wed, 29 Jun 2022 10:15:29 +0200 Subject: [PATCH] feat: api resource isolation configuration --- .../Localization-fr.json | 4 +++ src/Aguacongas.TheIdServer.Shared/SeedData.cs | 4 +++ .../Api.razor | 7 ++++ .../Entity/Api.cs | 7 ++++ ...guacongas.TheIdServer.MySql.Startup.csproj | 1 - .../Program.cs | 34 ++++++------------ ...uacongas.TheIdServer.Oracle.Startup.csproj | 10 ++++-- .../Program.cs | 35 ++++++------------- .../appsettings.json | 2 +- ...ngas.TheIdServer.PostgreSQL.Startup.csproj | 7 +++- .../Program.cs | 34 ++++++------------ ...ongas.TheIdServer.SqlServer.Startup.csproj | 1 - .../Program.cs | 33 ++++++----------- ...uacongas.TheIdServer.Sqlite.Startup.csproj | 7 +++- .../Program.cs | 34 ++++++------------ .../Extensions/EntityExtensions.cs | 5 ++- 16 files changed, 102 insertions(+), 123 deletions(-) diff --git a/src/Aguacongas.TheIdServer.Duende/Localization-fr.json b/src/Aguacongas.TheIdServer.Duende/Localization-fr.json index 586ed6edd..c842328d0 100644 --- a/src/Aguacongas.TheIdServer.Duende/Localization-fr.json +++ b/src/Aguacongas.TheIdServer.Duende/Localization-fr.json @@ -2126,5 +2126,9 @@ { "key": "claims cache sliding expiration", "value": "expiration du glissement du cache des réclamations" + }, + { + "key": "require resource indicator", + "value": "indicateur de resource requis" } ] \ No newline at end of file diff --git a/src/Aguacongas.TheIdServer.Shared/SeedData.cs b/src/Aguacongas.TheIdServer.Shared/SeedData.cs index d2f8fa4a5..e7ce6c4c4 100644 --- a/src/Aguacongas.TheIdServer.Shared/SeedData.cs +++ b/src/Aguacongas.TheIdServer.Shared/SeedData.cs @@ -207,6 +207,10 @@ private static void SeedApis(IConfiguration configuration, IServiceProvider prov DisplayName = resource.DisplayName, Enabled = resource.Enabled, Id = resource.Name, + +#if DUENDE + RequireResourceIndicator = resource.RequireResourceIndicator +#endif }).GetAwaiter().GetResult(); } catch (ArgumentException) diff --git a/src/BlazorApp/Aguacongas.TheIdServer.BlazorApp.Pages.Api/Api.razor b/src/BlazorApp/Aguacongas.TheIdServer.BlazorApp.Pages.Api/Api.razor index bad59d90c..4ecb02b14 100644 --- a/src/BlazorApp/Aguacongas.TheIdServer.BlazorApp.Pages.Api/Api.razor +++ b/src/BlazorApp/Aguacongas.TheIdServer.BlazorApp.Pages.Api/Api.razor @@ -96,6 +96,13 @@ else +
+ +
+ +
+
diff --git a/src/IdentityServer/Aguacongas.IdentityServer.Store/Entity/Api.cs b/src/IdentityServer/Aguacongas.IdentityServer.Store/Entity/Api.cs index fb900ede0..57bb92ec5 100644 --- a/src/IdentityServer/Aguacongas.IdentityServer.Store/Entity/Api.cs +++ b/src/IdentityServer/Aguacongas.IdentityServer.Store/Entity/Api.cs @@ -56,6 +56,13 @@ public class ProtectResource : IAuditable, ICloneable, ILocaliz /// public bool NonEditable { get; set; } + /// + /// Indicates if this API resource requires the resource indicator to request it, + /// and expects access tokens issued to it will only ever contain this API resource + /// as the audience. + /// + public bool RequireResourceIndicator { get; set; } + /// /// Gets or sets the secrets. /// diff --git a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.MySql.Startup/Aguacongas.TheIdServer.MySql.Startup.csproj b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.MySql.Startup/Aguacongas.TheIdServer.MySql.Startup.csproj index f8c590edc..d9cc4bdba 100644 --- a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.MySql.Startup/Aguacongas.TheIdServer.MySql.Startup.csproj +++ b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.MySql.Startup/Aguacongas.TheIdServer.MySql.Startup.csproj @@ -4,7 +4,6 @@ Exe net6.0 Aguacongas.TheIdServer.MySql - Aguacongas.TheIdServer.MySql.Program Olivier Lefebvre Copyright (c) 2022 @Olivier Lefebvre Apache-2.0 diff --git a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.MySql.Startup/Program.cs b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.MySql.Startup/Program.cs index a2c71465b..1297492a4 100644 --- a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.MySql.Startup/Program.cs +++ b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.MySql.Startup/Program.cs @@ -2,36 +2,24 @@ // Copyright (c) 2022 @Olivier Lefebvre using Aguacongas.IdentityServer.EntityFramework.Store; using Aguacongas.TheIdServer.Data; -using Aguacongas.TheIdServer.Models; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using System; -using System.Diagnostics.CodeAnalysis; -namespace Aguacongas.TheIdServer.MySql -{ - [SuppressMessage("Major Code Smell", "S1118:Utility classes should not have public constructors", Justification = "")] - public class Program +var host = Host.CreateDefaultBuilder(args) + .ConfigureAppConfiguration(builder => builder.AddJsonFile("appsettings.json")) + .ConfigureServices((hostContext, services) => { - public static void Main(string[] args) - { - CreateHostBuilder(args).Build().Run(); - } + var cn = hostContext.Configuration.GetConnectionString("db"); - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureAppConfiguration(builder => builder.AddJsonFile("appsettings.json")) - .ConfigureServices((hostContext, services) => - { - var cn = hostContext.Configuration.GetConnectionString("db"); + Action optionsAction = options => options.UseMySql(cn, ServerVersion.AutoDetect(cn), options => options.MigrationsAssembly("Aguacongas.TheIdServer.Migrations.MySql")); + services.AddDbContext(optionsAction) + .AddDbContext(optionsAction) + .AddDbContext(optionsAction); + }); - Action optionsAction = options => options.UseMySql(cn, ServerVersion.AutoDetect(cn), options => options.MigrationsAssembly("Aguacongas.TheIdServer.Migrations.MySql")); - services.AddDbContext(optionsAction) - .AddDbContext(optionsAction) - .AddDbContext(optionsAction); - }); +var app = host.Build(); - } -} +await app.RunAsync(); \ No newline at end of file diff --git a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Oracle.Startup/Aguacongas.TheIdServer.Oracle.Startup.csproj b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Oracle.Startup/Aguacongas.TheIdServer.Oracle.Startup.csproj index b2ba9c42c..912063fa8 100644 --- a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Oracle.Startup/Aguacongas.TheIdServer.Oracle.Startup.csproj +++ b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Oracle.Startup/Aguacongas.TheIdServer.Oracle.Startup.csproj @@ -4,7 +4,6 @@ Exe net6.0 Aguacongas.TheIdServer.Oracle - Aguacongas.TheIdServer.Oracle.Program Olivier Lefebvre Copyright (c) 2022 @Olivier Lefebvre Apache-2.0 @@ -13,7 +12,8 @@ git false ..\..\..\..\.sonarlint\aguacongas_theidservercsharp.ruleset - + enable + enable @@ -31,4 +31,10 @@ + + + PreserveNewest + + + diff --git a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Oracle.Startup/Program.cs b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Oracle.Startup/Program.cs index 742b65b4b..5b48dbaaa 100644 --- a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Oracle.Startup/Program.cs +++ b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Oracle.Startup/Program.cs @@ -2,36 +2,23 @@ // Copyright (c) 2022 @Olivier Lefebvre using Aguacongas.IdentityServer.EntityFramework.Store; using Aguacongas.TheIdServer.Data; -using Aguacongas.TheIdServer.Models; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using System; -using System.Diagnostics.CodeAnalysis; -namespace Aguacongas.TheIdServer.Oracle -{ - [SuppressMessage("Major Code Smell", "S1118:Utility classes should not have public constructors", Justification = "")] - public class Program +var host = Host.CreateDefaultBuilder(args) + .ConfigureAppConfiguration(builder => builder.AddJsonFile("appsettings.json")) + .ConfigureServices((hostContext, services) => { - public static void Main(string[] args) - { - CreateHostBuilder(args).Build().Run(); - } + var cn = hostContext.Configuration.GetConnectionString("db"); - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureAppConfiguration(builder => builder.AddJsonFile("appsettings.json")) - .ConfigureServices((hostContext, services) => - { - var cn = hostContext.Configuration.GetConnectionString("db"); + Action optionsAction = options => options.UseOracle(cn, options => options.MigrationsAssembly("Aguacongas.TheIdServer.Migrations.Oracle")); + services.AddDbContext(optionsAction) + .AddDbContext(optionsAction) + .AddDbContext(optionsAction); + }); - Action optionsAction = options => options.UseOracle(cn, options => options.MigrationsAssembly("Aguacongas.TheIdServer.Migrations.Oracle")); - services.AddDbContext(optionsAction) - .AddDbContext(optionsAction) - .AddDbContext(optionsAction); - }); +var app = host.Build(); - } -} +await app.RunAsync(); diff --git a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Oracle.Startup/appsettings.json b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Oracle.Startup/appsettings.json index 073d26f94..9d70e09a3 100644 --- a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Oracle.Startup/appsettings.json +++ b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Oracle.Startup/appsettings.json @@ -1,5 +1,5 @@ { "ConnectionStrings": { - "db": "server=localhost;connect mode=SysDba;direct=True;service name=ORCLCDB.localdomain;user id=sys;password=Oradoc_db1" + "db": "server=localhost;connect mode=SysDba;direct=True;service name=ORCLCDB.localdomain;user id=sys;password=I2bnR1iD4X;License Key=utsgvkT8r1j0sszGsNKxQSBlvJuZ6IrsIc+y7aJ85Oh4/UJ9OYM0qT53OaInE8 qYosRr4YHX40ODF0BICuUXBO7zcBU0RMVULdANq2PlWZtS87MnuWXh4TcciW0j5Ttv39XGzwcaOWbh3fTNEZNn9dctxnB1gpQulQnmHAmh1kxMPAXZLF59tEkYJjWM3ajK4OI87C7NpNHpgQR/yOvychJggWxE4T1q7+xdBqop4b8Bq4+Xzni4//xloTZ8Jgu7y0V4m0NMGlpVAOE9OjgQyZI7dTpwK4DemhgZSmJxBZRtvy9hgdjBz+f2LlowVLYQ" } } \ No newline at end of file diff --git a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.PostgreSQL.Startup/Aguacongas.TheIdServer.PostgreSQL.Startup.csproj b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.PostgreSQL.Startup/Aguacongas.TheIdServer.PostgreSQL.Startup.csproj index 911c66b76..793957426 100644 --- a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.PostgreSQL.Startup/Aguacongas.TheIdServer.PostgreSQL.Startup.csproj +++ b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.PostgreSQL.Startup/Aguacongas.TheIdServer.PostgreSQL.Startup.csproj @@ -4,7 +4,6 @@ Exe net6.0 Aguacongas.TheIdServer.PostgreSQL - Aguacongas.TheIdServer.PostgreSQL.Program Olivier Lefebvre Copyright (c) 2022 @Olivier Lefebvre Apache-2.0 @@ -31,4 +30,10 @@ + + + PreserveNewest + + + diff --git a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.PostgreSQL.Startup/Program.cs b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.PostgreSQL.Startup/Program.cs index d3fe8dccf..94ac34c67 100644 --- a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.PostgreSQL.Startup/Program.cs +++ b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.PostgreSQL.Startup/Program.cs @@ -2,36 +2,24 @@ // Copyright (c) 2022 @Olivier Lefebvre using Aguacongas.IdentityServer.EntityFramework.Store; using Aguacongas.TheIdServer.Data; -using Aguacongas.TheIdServer.Models; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using System; -using System.Diagnostics.CodeAnalysis; -namespace Aguacongas.TheIdServer.PostgreSQL -{ - [SuppressMessage("Major Code Smell", "S1118:Utility classes should not have public constructors", Justification = "")] - public class Program +var host = Host.CreateDefaultBuilder(args) + .ConfigureAppConfiguration(builder => builder.AddJsonFile("appsettings.json")) + .ConfigureServices((hostContext, services) => { - public static void Main(string[] args) - { - CreateHostBuilder(args).Build().Run(); - } + var cn = hostContext.Configuration.GetConnectionString("db"); - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureAppConfiguration(builder => builder.AddJsonFile("appsettings.json")) - .ConfigureServices((hostContext, services) => - { - var cn = hostContext.Configuration.GetConnectionString("db"); + Action optionsAction = options => options.UseNpgsql(cn, options => options.MigrationsAssembly("Aguacongas.TheIdServer.Migrations.PostgreSQL")); + services.AddDbContext(optionsAction) + .AddDbContext(optionsAction) + .AddDbContext(optionsAction); + }); - Action optionsAction = options => options.UseNpgsql(cn, options => options.MigrationsAssembly("Aguacongas.TheIdServer.Migrations.PostgreSQL")); - services.AddDbContext(optionsAction) - .AddDbContext(optionsAction) - .AddDbContext(optionsAction); - }); +var app = host.Build(); - } -} +await app.RunAsync(); \ No newline at end of file diff --git a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.SqlServer.Startup/Aguacongas.TheIdServer.SqlServer.Startup.csproj b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.SqlServer.Startup/Aguacongas.TheIdServer.SqlServer.Startup.csproj index 6f628f298..031b4a281 100644 --- a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.SqlServer.Startup/Aguacongas.TheIdServer.SqlServer.Startup.csproj +++ b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.SqlServer.Startup/Aguacongas.TheIdServer.SqlServer.Startup.csproj @@ -4,7 +4,6 @@ Exe net6.0 Aguacongas.TheIdServer.SqlServer - Aguacongas.TheIdServer.SqlServer.Program Olivier Lefebvre Copyright (c) 2022 @Olivier Lefebvre Apache-2.0 diff --git a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.SqlServer.Startup/Program.cs b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.SqlServer.Startup/Program.cs index d23d2608c..3aa33a34f 100644 --- a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.SqlServer.Startup/Program.cs +++ b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.SqlServer.Startup/Program.cs @@ -7,30 +7,19 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using System; -using System.Diagnostics.CodeAnalysis; -namespace Aguacongas.TheIdServer.SqlServer -{ - [SuppressMessage("Major Code Smell", "S1118:Utility classes should not have public constructors", Justification = "")] - public class Program +var host = Host.CreateDefaultBuilder(args) + .ConfigureAppConfiguration(builder => builder.AddJsonFile("appsettings.json")) + .ConfigureServices((hostContext, services) => { - public static void Main(string[] args) - { - CreateHostBuilder(args).Build().Run(); - } + var cn = hostContext.Configuration.GetConnectionString("db"); - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureAppConfiguration(builder => builder.AddJsonFile("appsettings.json")) - .ConfigureServices((hostContext, services) => - { - var cn = hostContext.Configuration.GetConnectionString("db"); + Action optionsAction = options => options.UseSqlServer(cn, options => options.MigrationsAssembly("Aguacongas.TheIdServer.Migrations.SqlServer")); + services.AddDbContext(optionsAction) + .AddDbContext(optionsAction) + .AddDbContext(optionsAction); + }); - Action optionsAction = options => options.UseSqlServer(cn, options => options.MigrationsAssembly("Aguacongas.TheIdServer.Migrations.SqlServer")); - services.AddDbContext(optionsAction) - .AddDbContext(optionsAction) - .AddDbContext(optionsAction); - }); +var app = host.Build(); - } -} +await app.RunAsync(); \ No newline at end of file diff --git a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Sqlite.Startup/Aguacongas.TheIdServer.Sqlite.Startup.csproj b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Sqlite.Startup/Aguacongas.TheIdServer.Sqlite.Startup.csproj index 2aa7a4807..b8a42a3a7 100644 --- a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Sqlite.Startup/Aguacongas.TheIdServer.Sqlite.Startup.csproj +++ b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Sqlite.Startup/Aguacongas.TheIdServer.Sqlite.Startup.csproj @@ -4,7 +4,6 @@ Exe net6.0 Aguacongas.TheIdServer.Sqlite - Aguacongas.TheIdServer.Sqlite.Program Olivier Lefebvre Copyright (c) 2022 @Olivier Lefebvre Apache-2.0 @@ -31,4 +30,10 @@ + + + PreserveNewest + + + diff --git a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Sqlite.Startup/Program.cs b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Sqlite.Startup/Program.cs index ca3b9daac..1843814b0 100644 --- a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Sqlite.Startup/Program.cs +++ b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Sqlite.Startup/Program.cs @@ -2,36 +2,24 @@ // Copyright (c) 2022 @Olivier Lefebvre using Aguacongas.IdentityServer.EntityFramework.Store; using Aguacongas.TheIdServer.Data; -using Aguacongas.TheIdServer.Models; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using System; -using System.Diagnostics.CodeAnalysis; -namespace Aguacongas.TheIdServer.Sqlite -{ - [SuppressMessage("Major Code Smell", "S1118:Utility classes should not have public constructors", Justification = "")] - public class Program +var host = Host.CreateDefaultBuilder(args) + .ConfigureAppConfiguration(builder => builder.AddJsonFile("appsettings.json")) + .ConfigureServices((hostContext, services) => { - public static void Main(string[] args) - { - CreateHostBuilder(args).Build().Run(); - } + var cn = hostContext.Configuration.GetConnectionString("db"); - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureAppConfiguration(builder => builder.AddJsonFile("appsettings.json")) - .ConfigureServices((hostContext, services) => - { - var cn = hostContext.Configuration.GetConnectionString("db"); + Action optionsAction = options => options.UseSqlite(cn, options => options.MigrationsAssembly("Aguacongas.TheIdServer.Migrations.Sqlite")); + services.AddDbContext(optionsAction) + .AddDbContext(optionsAction) + .AddDbContext(optionsAction); + }); - Action optionsAction = options => options.UseSqlite(cn, options => options.MigrationsAssembly("Aguacongas.TheIdServer.Migrations.Sqlite")); - services.AddDbContext(optionsAction) - .AddDbContext(optionsAction) - .AddDbContext(optionsAction); - }); +var app = host.Build(); - } -} +await app.RunAsync(); \ No newline at end of file diff --git a/src/IdentityServer/Shared/Aguacongas.IdentityServer.Shared/Extensions/EntityExtensions.cs b/src/IdentityServer/Shared/Aguacongas.IdentityServer.Shared/Extensions/EntityExtensions.cs index 7db577503..0bc86d502 100644 --- a/src/IdentityServer/Shared/Aguacongas.IdentityServer.Shared/Extensions/EntityExtensions.cs +++ b/src/IdentityServer/Shared/Aguacongas.IdentityServer.Shared/Extensions/EntityExtensions.cs @@ -137,7 +137,10 @@ public static ApiResource ToApi(this Entity.ProtectResource api) Name = api.Id, Properties = api.Properties.ToDictionary(p => p.Key, p => p.Value), Scopes = api.ApiScopes.Select(s => s.ApiScopeId).ToList(), - UserClaims = api.ApiClaims.Select(c => c.Type).ToList() + UserClaims = api.ApiClaims.Select(c => c.Type).ToList(), +#if DUENDE + RequireResourceIndicator = api.RequireResourceIndicator +#endif }; }