diff --git a/IdentityServer/v7/Apis/SimpleApi/Program.cs b/IdentityServer/v7/Apis/SimpleApi/Program.cs index 4e550d0d..17ca3b40 100755 --- a/IdentityServer/v7/Apis/SimpleApi/Program.cs +++ b/IdentityServer/v7/Apis/SimpleApi/Program.cs @@ -21,7 +21,7 @@ builder.Services.AddControllers(); -// this API will accept any access token from the authority +// Attention: This API will accept any access token from the authority in this configuration builder.Services.AddAuthentication("token") .AddJwtBearer("token", options => { @@ -32,6 +32,12 @@ options.MapInboundClaims = false; }); +// To require a scope, use a policy like this and apply it +builder.Services.AddAuthorization(options => +{ + options.AddPolicy("SimpleApi", p => p.RequireClaim("scope", "SimpleApi")); +}); + var app = builder.Build(); app.UseRouting(); @@ -39,5 +45,6 @@ app.UseAuthorization(); app.MapControllers().RequireAuthorization(); +//app.MapControllers().RequireAuthorization("SimpleApi"); app.Run(); diff --git a/IdentityServer/v7/Configuration/IdentityServerHost/Properties/launchSettings.json b/IdentityServer/v7/Configuration/IdentityServerHost/Properties/launchSettings.json index c6f7da98..68005125 100644 --- a/IdentityServer/v7/Configuration/IdentityServerHost/Properties/launchSettings.json +++ b/IdentityServer/v7/Configuration/IdentityServerHost/Properties/launchSettings.json @@ -1,6 +1,6 @@ { "profiles": { - "Self": { + "SelfHost": { "commandName": "Project", "launchBrowser": true, "environmentVariables": { diff --git a/IdentityServer/v7/Configuration/Permissions/Configuration/Properties/launchSettings.json b/IdentityServer/v7/Configuration/Permissions/Configuration/Properties/launchSettings.json index 6933ff5c..91452ab7 100644 --- a/IdentityServer/v7/Configuration/Permissions/Configuration/Properties/launchSettings.json +++ b/IdentityServer/v7/Configuration/Permissions/Configuration/Properties/launchSettings.json @@ -4,7 +4,7 @@ "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": false, - "applicationUrl": "https://localhost:5002", + "applicationUrl": "https://localhost:5003", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/IdentityServer/v7/Configuration/Permissions/ConsoleDcrClient/Constants.cs b/IdentityServer/v7/Configuration/Permissions/ConsoleDcrClient/Constants.cs index 51e38094..9671721b 100644 --- a/IdentityServer/v7/Configuration/Permissions/ConsoleDcrClient/Constants.cs +++ b/IdentityServer/v7/Configuration/Permissions/ConsoleDcrClient/Constants.cs @@ -6,5 +6,6 @@ namespace ConsoleDcrClient; public class Constants { public const string Authority = "https://localhost:5001"; - public const string SimpleApi = "https://localhost:6001/"; + public const string SimpleApi = "https://localhost:5002/"; + public const string ConfigurationApi = "https://localhost:5003"; } diff --git a/IdentityServer/v7/Configuration/Permissions/ConsoleDcrClient/Program.cs b/IdentityServer/v7/Configuration/Permissions/ConsoleDcrClient/Program.cs index 4262fdce..2bffad9f 100644 --- a/IdentityServer/v7/Configuration/Permissions/ConsoleDcrClient/Program.cs +++ b/IdentityServer/v7/Configuration/Permissions/ConsoleDcrClient/Program.cs @@ -49,7 +49,7 @@ static async Task RegisterClient(string acces var request = new DynamicClientRegistrationRequest { - Address = "https://localhost:5002/connect/dcr", + Address = $"{Constants.ConfigurationApi}/connect/dcr", Document = new DynamicClientRegistrationDocument { @@ -77,7 +77,7 @@ static async Task RequestTokenAsync(string clientId = "client", s { var client = new HttpClient(); - var disco = await client.GetDiscoveryDocumentAsync("https://localhost:5001"); + var disco = await client.GetDiscoveryDocumentAsync(Constants.Authority); if (disco.IsError) throw new Exception(disco.Error); var response = await client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest diff --git a/IdentityServer/v7/Configuration/Permissions/Permissions.sln b/IdentityServer/v7/Configuration/Permissions/Permissions.sln index 24e77037..94968a8d 100644 --- a/IdentityServer/v7/Configuration/Permissions/Permissions.sln +++ b/IdentityServer/v7/Configuration/Permissions/Permissions.sln @@ -7,10 +7,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Configuration", "Configurat EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleDcrClient", "ConsoleDcrClient\ConsoleDcrClient.csproj", "{D134466E-58AE-4787-984B-FB6F95EEA969}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleApi", "SimpleApi\SimpleApi.csproj", "{CCAA779F-8528-4351-8333-80B60A7C4FAC}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IdentityServer", "..\IdentityServerHost\IdentityServer.csproj", "{075FD8FE-6A12-4121-9163-F2A48001F37B}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleApi", "..\..\Apis\SimpleApi\SimpleApi.csproj", "{52E6BB46-1B26-431D-B13E-D58734BFF1B2}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -28,13 +28,13 @@ Global {D134466E-58AE-4787-984B-FB6F95EEA969}.Debug|Any CPU.Build.0 = Debug|Any CPU {D134466E-58AE-4787-984B-FB6F95EEA969}.Release|Any CPU.ActiveCfg = Release|Any CPU {D134466E-58AE-4787-984B-FB6F95EEA969}.Release|Any CPU.Build.0 = Release|Any CPU - {CCAA779F-8528-4351-8333-80B60A7C4FAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {CCAA779F-8528-4351-8333-80B60A7C4FAC}.Debug|Any CPU.Build.0 = Debug|Any CPU - {CCAA779F-8528-4351-8333-80B60A7C4FAC}.Release|Any CPU.ActiveCfg = Release|Any CPU - {CCAA779F-8528-4351-8333-80B60A7C4FAC}.Release|Any CPU.Build.0 = Release|Any CPU {075FD8FE-6A12-4121-9163-F2A48001F37B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {075FD8FE-6A12-4121-9163-F2A48001F37B}.Debug|Any CPU.Build.0 = Debug|Any CPU {075FD8FE-6A12-4121-9163-F2A48001F37B}.Release|Any CPU.ActiveCfg = Release|Any CPU {075FD8FE-6A12-4121-9163-F2A48001F37B}.Release|Any CPU.Build.0 = Release|Any CPU + {52E6BB46-1B26-431D-B13E-D58734BFF1B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {52E6BB46-1B26-431D-B13E-D58734BFF1B2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {52E6BB46-1B26-431D-B13E-D58734BFF1B2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {52E6BB46-1B26-431D-B13E-D58734BFF1B2}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/IdentityServer/v7/Configuration/Permissions/SimpleApi/IdentityController.cs b/IdentityServer/v7/Configuration/Permissions/SimpleApi/IdentityController.cs deleted file mode 100644 index 17104505..00000000 --- a/IdentityServer/v7/Configuration/Permissions/SimpleApi/IdentityController.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) Duende Software. All rights reserved. -// Licensed under the MIT License. See LICENSE in the project root for license information. - -using Microsoft.AspNetCore.Mvc; - -namespace SimpleApi.Controllers; - -[Route("identity")] -public class IdentityController : ControllerBase -{ - private readonly ILogger _logger; - - public IdentityController(ILogger logger) - { - _logger = logger; - } - - [HttpGet] - public ActionResult Get() - { - var claims = User.Claims.Select(c => new { c.Type, c.Value }); - _logger.LogInformation("claims: {claims}", claims); - - return new JsonResult(claims); - } -} diff --git a/IdentityServer/v7/Configuration/Permissions/SimpleApi/Program.cs b/IdentityServer/v7/Configuration/Permissions/SimpleApi/Program.cs deleted file mode 100644 index 3d9a58af..00000000 --- a/IdentityServer/v7/Configuration/Permissions/SimpleApi/Program.cs +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) Duende Software. All rights reserved. -// Licensed under the MIT License. See LICENSE in the project root for license information. - -using Serilog; -using Serilog.Sinks.SystemConsole.Themes; - -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 => - { - 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(); diff --git a/IdentityServer/v7/Configuration/Permissions/SimpleApi/Properties/launchSettings.json b/IdentityServer/v7/Configuration/Permissions/SimpleApi/Properties/launchSettings.json deleted file mode 100644 index 50945d8e..00000000 --- a/IdentityServer/v7/Configuration/Permissions/SimpleApi/Properties/launchSettings.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "profiles": { - "Api": { - "commandName": "Project", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - }, - "applicationUrl": "https://localhost:6001" - } - } -} \ No newline at end of file diff --git a/IdentityServer/v7/Configuration/Permissions/SimpleApi/SimpleApi.csproj b/IdentityServer/v7/Configuration/Permissions/SimpleApi/SimpleApi.csproj deleted file mode 100644 index dab4fda0..00000000 --- a/IdentityServer/v7/Configuration/Permissions/SimpleApi/SimpleApi.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - - net10.0 - enable - - - - - - - - diff --git a/IdentityServer/v7/Configuration/PipelineRegistration/Configuration/Properties/launchSettings.json b/IdentityServer/v7/Configuration/PipelineRegistration/Configuration/Properties/launchSettings.json index 0b6837fd..91452ab7 100644 --- a/IdentityServer/v7/Configuration/PipelineRegistration/Configuration/Properties/launchSettings.json +++ b/IdentityServer/v7/Configuration/PipelineRegistration/Configuration/Properties/launchSettings.json @@ -3,11 +3,11 @@ "https": { "commandName": "Project", "dotnetRunMessages": true, - "launchBrowser": true, - "applicationUrl": "https://localhost:5002", + "launchBrowser": false, + "applicationUrl": "https://localhost:5003", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } } } -} \ No newline at end of file +} diff --git a/IdentityServer/v7/Configuration/PipelineRegistration/ConsoleDcrClient/Constants.cs b/IdentityServer/v7/Configuration/PipelineRegistration/ConsoleDcrClient/Constants.cs index 51e38094..9671721b 100644 --- a/IdentityServer/v7/Configuration/PipelineRegistration/ConsoleDcrClient/Constants.cs +++ b/IdentityServer/v7/Configuration/PipelineRegistration/ConsoleDcrClient/Constants.cs @@ -6,5 +6,6 @@ namespace ConsoleDcrClient; public class Constants { public const string Authority = "https://localhost:5001"; - public const string SimpleApi = "https://localhost:6001/"; + public const string SimpleApi = "https://localhost:5002/"; + public const string ConfigurationApi = "https://localhost:5003"; } diff --git a/IdentityServer/v7/Configuration/PipelineRegistration/ConsoleDcrClient/Program.cs b/IdentityServer/v7/Configuration/PipelineRegistration/ConsoleDcrClient/Program.cs index beacc802..e54ff2cd 100644 --- a/IdentityServer/v7/Configuration/PipelineRegistration/ConsoleDcrClient/Program.cs +++ b/IdentityServer/v7/Configuration/PipelineRegistration/ConsoleDcrClient/Program.cs @@ -56,7 +56,7 @@ static async Task RegisterClient(string acces var request = new DynamicClientRegistrationRequest { - Address = "https://localhost:5002/connect/dcr", + Address = $"{Constants.ConfigurationApi}/connect/dcr", Document = new DynamicClientRegistrationDocument { @@ -81,7 +81,7 @@ static async Task RequestTokenAsync(string clientId, string clien { var client = new HttpClient(); - var disco = await client.GetDiscoveryDocumentAsync("https://localhost:5001"); + var disco = await client.GetDiscoveryDocumentAsync(Constants.Authority); if (disco.IsError) throw new Exception(disco.Error); var response = await client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest diff --git a/IdentityServer/v7/Configuration/PipelineRegistration/PipelineRegistration.sln b/IdentityServer/v7/Configuration/PipelineRegistration/PipelineRegistration.sln index d5251d41..dbd1cf24 100644 --- a/IdentityServer/v7/Configuration/PipelineRegistration/PipelineRegistration.sln +++ b/IdentityServer/v7/Configuration/PipelineRegistration/PipelineRegistration.sln @@ -7,10 +7,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Configuration", "Configurat EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleDcrClient", "ConsoleDcrClient\ConsoleDcrClient.csproj", "{D134466E-58AE-4787-984B-FB6F95EEA969}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleApi", "SimpleApi\SimpleApi.csproj", "{238947E4-9433-4CC5-B4A6-0E8EC935A9F6}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IdentityServer", "..\IdentityServerHost\IdentityServer.csproj", "{E0A37C31-D760-4CE0-925B-756BDDE6EFAA}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleApi", "..\..\Apis\SimpleApi\SimpleApi.csproj", "{1F141D4D-C27D-4A94-B518-80369AFE33E2}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -28,13 +28,13 @@ Global {D134466E-58AE-4787-984B-FB6F95EEA969}.Debug|Any CPU.Build.0 = Debug|Any CPU {D134466E-58AE-4787-984B-FB6F95EEA969}.Release|Any CPU.ActiveCfg = Release|Any CPU {D134466E-58AE-4787-984B-FB6F95EEA969}.Release|Any CPU.Build.0 = Release|Any CPU - {238947E4-9433-4CC5-B4A6-0E8EC935A9F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {238947E4-9433-4CC5-B4A6-0E8EC935A9F6}.Debug|Any CPU.Build.0 = Debug|Any CPU - {238947E4-9433-4CC5-B4A6-0E8EC935A9F6}.Release|Any CPU.ActiveCfg = Release|Any CPU - {238947E4-9433-4CC5-B4A6-0E8EC935A9F6}.Release|Any CPU.Build.0 = Release|Any CPU {E0A37C31-D760-4CE0-925B-756BDDE6EFAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {E0A37C31-D760-4CE0-925B-756BDDE6EFAA}.Debug|Any CPU.Build.0 = Debug|Any CPU {E0A37C31-D760-4CE0-925B-756BDDE6EFAA}.Release|Any CPU.ActiveCfg = Release|Any CPU {E0A37C31-D760-4CE0-925B-756BDDE6EFAA}.Release|Any CPU.Build.0 = Release|Any CPU + {1F141D4D-C27D-4A94-B518-80369AFE33E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1F141D4D-C27D-4A94-B518-80369AFE33E2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1F141D4D-C27D-4A94-B518-80369AFE33E2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1F141D4D-C27D-4A94-B518-80369AFE33E2}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/IdentityServer/v7/Configuration/PipelineRegistration/SimpleApi/IdentityController.cs b/IdentityServer/v7/Configuration/PipelineRegistration/SimpleApi/IdentityController.cs deleted file mode 100644 index 17104505..00000000 --- a/IdentityServer/v7/Configuration/PipelineRegistration/SimpleApi/IdentityController.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) Duende Software. All rights reserved. -// Licensed under the MIT License. See LICENSE in the project root for license information. - -using Microsoft.AspNetCore.Mvc; - -namespace SimpleApi.Controllers; - -[Route("identity")] -public class IdentityController : ControllerBase -{ - private readonly ILogger _logger; - - public IdentityController(ILogger logger) - { - _logger = logger; - } - - [HttpGet] - public ActionResult Get() - { - var claims = User.Claims.Select(c => new { c.Type, c.Value }); - _logger.LogInformation("claims: {claims}", claims); - - return new JsonResult(claims); - } -} diff --git a/IdentityServer/v7/Configuration/PipelineRegistration/SimpleApi/Program.cs b/IdentityServer/v7/Configuration/PipelineRegistration/SimpleApi/Program.cs deleted file mode 100644 index acdafeb3..00000000 --- a/IdentityServer/v7/Configuration/PipelineRegistration/SimpleApi/Program.cs +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) Duende Software. All rights reserved. -// Licensed under the MIT License. See LICENSE in the project root for license information. - -using Serilog; -using Serilog.Sinks.SystemConsole.Themes; - -Console.Title = "Sample 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 => - { - 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(); - diff --git a/IdentityServer/v7/Configuration/PipelineRegistration/SimpleApi/Properties/launchSettings.json b/IdentityServer/v7/Configuration/PipelineRegistration/SimpleApi/Properties/launchSettings.json deleted file mode 100644 index 50945d8e..00000000 --- a/IdentityServer/v7/Configuration/PipelineRegistration/SimpleApi/Properties/launchSettings.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "profiles": { - "Api": { - "commandName": "Project", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - }, - "applicationUrl": "https://localhost:6001" - } - } -} \ No newline at end of file diff --git a/IdentityServer/v7/Configuration/PipelineRegistration/SimpleApi/SimpleApi.csproj b/IdentityServer/v7/Configuration/PipelineRegistration/SimpleApi/SimpleApi.csproj deleted file mode 100644 index ea61b4bb..00000000 --- a/IdentityServer/v7/Configuration/PipelineRegistration/SimpleApi/SimpleApi.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - - net10.0 - true - - - - - - - - diff --git a/IdentityServer/v7/Configuration/SimpleDcr/Configuration.sln b/IdentityServer/v7/Configuration/SimpleDcr/Configuration.sln index 4aef3df4..efa479ba 100644 --- a/IdentityServer/v7/Configuration/SimpleDcr/Configuration.sln +++ b/IdentityServer/v7/Configuration/SimpleDcr/Configuration.sln @@ -7,10 +7,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Configuration", "Configurat EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleDcrClient", "ConsoleDcrClient\ConsoleDcrClient.csproj", "{D134466E-58AE-4787-984B-FB6F95EEA969}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleApi", "SimpleApi\SimpleApi.csproj", "{8AEE27BD-A162-431C-8579-79EF07B5B618}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IdentityServer", "..\IdentityServerHost\IdentityServer.csproj", "{84D25756-275F-4BB1-AFAC-E9FD568102EE}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleApi", "..\..\Apis\SimpleApi\SimpleApi.csproj", "{BCE427BA-E794-4956-AA68-FA0CAE184DFA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -28,13 +28,13 @@ Global {D134466E-58AE-4787-984B-FB6F95EEA969}.Debug|Any CPU.Build.0 = Debug|Any CPU {D134466E-58AE-4787-984B-FB6F95EEA969}.Release|Any CPU.ActiveCfg = Release|Any CPU {D134466E-58AE-4787-984B-FB6F95EEA969}.Release|Any CPU.Build.0 = Release|Any CPU - {8AEE27BD-A162-431C-8579-79EF07B5B618}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8AEE27BD-A162-431C-8579-79EF07B5B618}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8AEE27BD-A162-431C-8579-79EF07B5B618}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8AEE27BD-A162-431C-8579-79EF07B5B618}.Release|Any CPU.Build.0 = Release|Any CPU {84D25756-275F-4BB1-AFAC-E9FD568102EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {84D25756-275F-4BB1-AFAC-E9FD568102EE}.Debug|Any CPU.Build.0 = Debug|Any CPU {84D25756-275F-4BB1-AFAC-E9FD568102EE}.Release|Any CPU.ActiveCfg = Release|Any CPU {84D25756-275F-4BB1-AFAC-E9FD568102EE}.Release|Any CPU.Build.0 = Release|Any CPU + {BCE427BA-E794-4956-AA68-FA0CAE184DFA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BCE427BA-E794-4956-AA68-FA0CAE184DFA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BCE427BA-E794-4956-AA68-FA0CAE184DFA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BCE427BA-E794-4956-AA68-FA0CAE184DFA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/IdentityServer/v7/Configuration/SimpleDcr/Configuration/Properties/launchSettings.json b/IdentityServer/v7/Configuration/SimpleDcr/Configuration/Properties/launchSettings.json index 0b6837fd..317aeb78 100644 --- a/IdentityServer/v7/Configuration/SimpleDcr/Configuration/Properties/launchSettings.json +++ b/IdentityServer/v7/Configuration/SimpleDcr/Configuration/Properties/launchSettings.json @@ -4,10 +4,10 @@ "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, - "applicationUrl": "https://localhost:5002", + "applicationUrl": "https://localhost:5003", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } } } -} \ No newline at end of file +} diff --git a/IdentityServer/v7/Configuration/SimpleDcr/ConsoleDcrClient/Constants.cs b/IdentityServer/v7/Configuration/SimpleDcr/ConsoleDcrClient/Constants.cs index 51e38094..9671721b 100644 --- a/IdentityServer/v7/Configuration/SimpleDcr/ConsoleDcrClient/Constants.cs +++ b/IdentityServer/v7/Configuration/SimpleDcr/ConsoleDcrClient/Constants.cs @@ -6,5 +6,6 @@ namespace ConsoleDcrClient; public class Constants { public const string Authority = "https://localhost:5001"; - public const string SimpleApi = "https://localhost:6001/"; + public const string SimpleApi = "https://localhost:5002/"; + public const string ConfigurationApi = "https://localhost:5003"; } diff --git a/IdentityServer/v7/Configuration/SimpleDcr/ConsoleDcrClient/Program.cs b/IdentityServer/v7/Configuration/SimpleDcr/ConsoleDcrClient/Program.cs index 1996d42f..1dffae67 100644 --- a/IdentityServer/v7/Configuration/SimpleDcr/ConsoleDcrClient/Program.cs +++ b/IdentityServer/v7/Configuration/SimpleDcr/ConsoleDcrClient/Program.cs @@ -33,7 +33,7 @@ static async Task RegisterClient(string acces var request = new DynamicClientRegistrationRequest { - Address = "https://localhost:5002/connect/dcr", + Address = $"{Constants.ConfigurationApi}/connect/dcr", Document = new DynamicClientRegistrationDocument { @@ -58,7 +58,7 @@ static async Task RequestTokenAsync(string clientId = "client", s { var client = new HttpClient(); - var disco = await client.GetDiscoveryDocumentAsync("https://localhost:5001"); + var disco = await client.GetDiscoveryDocumentAsync(Constants.Authority); if (disco.IsError) throw new Exception(disco.Error); var response = await client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest diff --git a/IdentityServer/v7/Configuration/SimpleDcr/SimpleApi/IdentityController.cs b/IdentityServer/v7/Configuration/SimpleDcr/SimpleApi/IdentityController.cs deleted file mode 100644 index 17104505..00000000 --- a/IdentityServer/v7/Configuration/SimpleDcr/SimpleApi/IdentityController.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) Duende Software. All rights reserved. -// Licensed under the MIT License. See LICENSE in the project root for license information. - -using Microsoft.AspNetCore.Mvc; - -namespace SimpleApi.Controllers; - -[Route("identity")] -public class IdentityController : ControllerBase -{ - private readonly ILogger _logger; - - public IdentityController(ILogger logger) - { - _logger = logger; - } - - [HttpGet] - public ActionResult Get() - { - var claims = User.Claims.Select(c => new { c.Type, c.Value }); - _logger.LogInformation("claims: {claims}", claims); - - return new JsonResult(claims); - } -} diff --git a/IdentityServer/v7/Configuration/SimpleDcr/SimpleApi/Program.cs b/IdentityServer/v7/Configuration/SimpleDcr/SimpleApi/Program.cs deleted file mode 100644 index 2dca9f89..00000000 --- a/IdentityServer/v7/Configuration/SimpleDcr/SimpleApi/Program.cs +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) Duende Software. All rights reserved. -// Licensed under the MIT License. See LICENSE in the project root for license information. - -using Serilog; -using Serilog.Events; -using Serilog.Sinks.SystemConsole.Themes; - -Console.Title = "Sample API"; - -Log.Logger = new LoggerConfiguration() - .MinimumLevel.Verbose() - .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) - .MinimumLevel.Override("System", LogEventLevel.Warning) - .MinimumLevel.Override("Microsoft.AspNetCore.Authentication", LogEventLevel.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 => - { - 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(); diff --git a/IdentityServer/v7/Configuration/SimpleDcr/SimpleApi/Properties/launchSettings.json b/IdentityServer/v7/Configuration/SimpleDcr/SimpleApi/Properties/launchSettings.json deleted file mode 100644 index 50945d8e..00000000 --- a/IdentityServer/v7/Configuration/SimpleDcr/SimpleApi/Properties/launchSettings.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "profiles": { - "Api": { - "commandName": "Project", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - }, - "applicationUrl": "https://localhost:6001" - } - } -} \ No newline at end of file diff --git a/IdentityServer/v7/Configuration/SimpleDcr/SimpleApi/SimpleApi.csproj b/IdentityServer/v7/Configuration/SimpleDcr/SimpleApi/SimpleApi.csproj deleted file mode 100644 index ea61b4bb..00000000 --- a/IdentityServer/v7/Configuration/SimpleDcr/SimpleApi/SimpleApi.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - - net10.0 - true - - - - - - - - diff --git a/IdentityServer/v7/Configuration/SoftwareStatement/Configuration/Properties/launchSettings.json b/IdentityServer/v7/Configuration/SoftwareStatement/Configuration/Properties/launchSettings.json index 0b6837fd..91452ab7 100644 --- a/IdentityServer/v7/Configuration/SoftwareStatement/Configuration/Properties/launchSettings.json +++ b/IdentityServer/v7/Configuration/SoftwareStatement/Configuration/Properties/launchSettings.json @@ -3,11 +3,11 @@ "https": { "commandName": "Project", "dotnetRunMessages": true, - "launchBrowser": true, - "applicationUrl": "https://localhost:5002", + "launchBrowser": false, + "applicationUrl": "https://localhost:5003", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } } } -} \ No newline at end of file +} diff --git a/IdentityServer/v7/Configuration/SoftwareStatement/ConsoleDcrClient/Constants.cs b/IdentityServer/v7/Configuration/SoftwareStatement/ConsoleDcrClient/Constants.cs index 51e38094..9671721b 100644 --- a/IdentityServer/v7/Configuration/SoftwareStatement/ConsoleDcrClient/Constants.cs +++ b/IdentityServer/v7/Configuration/SoftwareStatement/ConsoleDcrClient/Constants.cs @@ -6,5 +6,6 @@ namespace ConsoleDcrClient; public class Constants { public const string Authority = "https://localhost:5001"; - public const string SimpleApi = "https://localhost:6001/"; + public const string SimpleApi = "https://localhost:5002/"; + public const string ConfigurationApi = "https://localhost:5003"; } diff --git a/IdentityServer/v7/Configuration/SoftwareStatement/ConsoleDcrClient/Program.cs b/IdentityServer/v7/Configuration/SoftwareStatement/ConsoleDcrClient/Program.cs index e72e74ed..01c8c66c 100644 --- a/IdentityServer/v7/Configuration/SoftwareStatement/ConsoleDcrClient/Program.cs +++ b/IdentityServer/v7/Configuration/SoftwareStatement/ConsoleDcrClient/Program.cs @@ -35,7 +35,7 @@ static async Task RegisterClient(string acces var request = new DynamicClientRegistrationRequest { - Address = "https://localhost:5002/connect/dcr", + Address = $"{Constants.ConfigurationApi}/connect/dcr", Document = new DynamicClientRegistrationDocument { GrantTypes = { "client_credentials" }, @@ -89,7 +89,7 @@ static async Task RequestTokenAsync(string clientId = "client", s { var client = new HttpClient(); - var disco = await client.GetDiscoveryDocumentAsync("https://localhost:5001"); + var disco = await client.GetDiscoveryDocumentAsync(Constants.Authority); if (disco.IsError) throw new Exception(disco.Error); var response = await client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest diff --git a/IdentityServer/v7/Configuration/SoftwareStatement/SimpleApi/IdentityController.cs b/IdentityServer/v7/Configuration/SoftwareStatement/SimpleApi/IdentityController.cs deleted file mode 100644 index 17104505..00000000 --- a/IdentityServer/v7/Configuration/SoftwareStatement/SimpleApi/IdentityController.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) Duende Software. All rights reserved. -// Licensed under the MIT License. See LICENSE in the project root for license information. - -using Microsoft.AspNetCore.Mvc; - -namespace SimpleApi.Controllers; - -[Route("identity")] -public class IdentityController : ControllerBase -{ - private readonly ILogger _logger; - - public IdentityController(ILogger logger) - { - _logger = logger; - } - - [HttpGet] - public ActionResult Get() - { - var claims = User.Claims.Select(c => new { c.Type, c.Value }); - _logger.LogInformation("claims: {claims}", claims); - - return new JsonResult(claims); - } -} diff --git a/IdentityServer/v7/Configuration/SoftwareStatement/SimpleApi/Program.cs b/IdentityServer/v7/Configuration/SoftwareStatement/SimpleApi/Program.cs deleted file mode 100644 index 2dca9f89..00000000 --- a/IdentityServer/v7/Configuration/SoftwareStatement/SimpleApi/Program.cs +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) Duende Software. All rights reserved. -// Licensed under the MIT License. See LICENSE in the project root for license information. - -using Serilog; -using Serilog.Events; -using Serilog.Sinks.SystemConsole.Themes; - -Console.Title = "Sample API"; - -Log.Logger = new LoggerConfiguration() - .MinimumLevel.Verbose() - .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) - .MinimumLevel.Override("System", LogEventLevel.Warning) - .MinimumLevel.Override("Microsoft.AspNetCore.Authentication", LogEventLevel.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 => - { - 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(); diff --git a/IdentityServer/v7/Configuration/SoftwareStatement/SimpleApi/Properties/launchSettings.json b/IdentityServer/v7/Configuration/SoftwareStatement/SimpleApi/Properties/launchSettings.json deleted file mode 100644 index 50945d8e..00000000 --- a/IdentityServer/v7/Configuration/SoftwareStatement/SimpleApi/Properties/launchSettings.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "profiles": { - "Api": { - "commandName": "Project", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - }, - "applicationUrl": "https://localhost:6001" - } - } -} \ No newline at end of file diff --git a/IdentityServer/v7/Configuration/SoftwareStatement/SimpleApi/SimpleApi.csproj b/IdentityServer/v7/Configuration/SoftwareStatement/SimpleApi/SimpleApi.csproj deleted file mode 100644 index ea61b4bb..00000000 --- a/IdentityServer/v7/Configuration/SoftwareStatement/SimpleApi/SimpleApi.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - - net10.0 - true - - - - - - - - diff --git a/IdentityServer/v7/Configuration/SoftwareStatement/SoftwareStatement.sln b/IdentityServer/v7/Configuration/SoftwareStatement/SoftwareStatement.sln index 2c3b8bbe..66f410de 100644 --- a/IdentityServer/v7/Configuration/SoftwareStatement/SoftwareStatement.sln +++ b/IdentityServer/v7/Configuration/SoftwareStatement/SoftwareStatement.sln @@ -7,10 +7,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Configuration", "Configurat EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleDcrClient", "ConsoleDcrClient\ConsoleDcrClient.csproj", "{D134466E-58AE-4787-984B-FB6F95EEA969}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleApi", "SimpleApi\SimpleApi.csproj", "{8AEE27BD-A162-431C-8579-79EF07B5B618}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IdentityServer", "..\IdentityServerHost\IdentityServer.csproj", "{EF303AD6-A579-47DB-A195-7DED0A835707}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleApi", "..\..\Apis\SimpleApi\SimpleApi.csproj", "{68EC0130-6288-4DCB-A6F6-15C4503A384D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -28,13 +28,13 @@ Global {D134466E-58AE-4787-984B-FB6F95EEA969}.Debug|Any CPU.Build.0 = Debug|Any CPU {D134466E-58AE-4787-984B-FB6F95EEA969}.Release|Any CPU.ActiveCfg = Release|Any CPU {D134466E-58AE-4787-984B-FB6F95EEA969}.Release|Any CPU.Build.0 = Release|Any CPU - {8AEE27BD-A162-431C-8579-79EF07B5B618}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8AEE27BD-A162-431C-8579-79EF07B5B618}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8AEE27BD-A162-431C-8579-79EF07B5B618}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8AEE27BD-A162-431C-8579-79EF07B5B618}.Release|Any CPU.Build.0 = Release|Any CPU {EF303AD6-A579-47DB-A195-7DED0A835707}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {EF303AD6-A579-47DB-A195-7DED0A835707}.Debug|Any CPU.Build.0 = Debug|Any CPU {EF303AD6-A579-47DB-A195-7DED0A835707}.Release|Any CPU.ActiveCfg = Release|Any CPU {EF303AD6-A579-47DB-A195-7DED0A835707}.Release|Any CPU.Build.0 = Release|Any CPU + {68EC0130-6288-4DCB-A6F6-15C4503A384D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {68EC0130-6288-4DCB-A6F6-15C4503A384D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {68EC0130-6288-4DCB-A6F6-15C4503A384D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {68EC0130-6288-4DCB-A6F6-15C4503A384D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/samples.slnx b/samples.slnx index 189d25fd..7740009c 100644 --- a/samples.slnx +++ b/samples.slnx @@ -151,22 +151,18 @@ - - - -