first cut

This commit is contained in:
Dominick Baier 2021-11-09 10:46:03 +01:00
parent ac2f1e26f5
commit 7c5a8d773b
36 changed files with 165 additions and 124 deletions

View file

@ -15,13 +15,8 @@
<PackageProjectUrl>https://github.com/DuendeSoftware/IdentityServer</PackageProjectUrl>
<PackageReleaseNotes>https://github.com/DuendeSoftware/IdentityServer/releases</PackageReleaseNotes>
<!-- Publish the repository URL in the built .nupkg (in the NuSpec <Repository> element) -->
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<!-- Embed source files that are not tracked by the source control manager in the PDB -->
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<!-- Recommended: Embed symbols containing Source Link in the main file (exe/dll) -->
<DebugType>embedded</DebugType>
<ContinuousIntegrationBuild Condition="'$(GITHUB_ACTIONS)' == 'true'">True</ContinuousIntegrationBuild>

View file

@ -67,7 +67,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleResourceIndicators",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MvcJarUriJwt", "src\MvcJarUriJwt\MvcJarUriJwt.csproj", "{0BC37D8C-5A67-4A4E-A562-AEBCC97A31D9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleCibaClient", "src\ConsoleClientCredentialsFlow\ConsoleCibaClient\ConsoleCibaClient.csproj", "{3024047C-FA85-4213-AEA2-0DEF0EC126B7}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleCibaClient", "src\ConsoleCibaClient\ConsoleCibaClient.csproj", "{5B89FD38-A096-4C9B-B39F-1FD6C591EE3D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -183,10 +183,10 @@ Global
{0BC37D8C-5A67-4A4E-A562-AEBCC97A31D9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0BC37D8C-5A67-4A4E-A562-AEBCC97A31D9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0BC37D8C-5A67-4A4E-A562-AEBCC97A31D9}.Release|Any CPU.Build.0 = Release|Any CPU
{3024047C-FA85-4213-AEA2-0DEF0EC126B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3024047C-FA85-4213-AEA2-0DEF0EC126B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3024047C-FA85-4213-AEA2-0DEF0EC126B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3024047C-FA85-4213-AEA2-0DEF0EC126B7}.Release|Any CPU.Build.0 = Release|Any CPU
{5B89FD38-A096-4C9B-B39F-1FD6C591EE3D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5B89FD38-A096-4C9B-B39F-1FD6C591EE3D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5B89FD38-A096-4C9B-B39F-1FD6C591EE3D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5B89FD38-A096-4C9B-B39F-1FD6C591EE3D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -222,7 +222,7 @@ Global
{68C3A94B-1CE1-4434-A59D-5119AF648C38} = {D027D36B-262B-450A-B444-5B7893B5142E}
{C07E9414-8AFF-4B71-8B28-76DA6250B94C} = {D027D36B-262B-450A-B444-5B7893B5142E}
{0BC37D8C-5A67-4A4E-A562-AEBCC97A31D9} = {158628D7-8B68-451E-AF22-B64F473C5943}
{3024047C-FA85-4213-AEA2-0DEF0EC126B7} = {D027D36B-262B-450A-B444-5B7893B5142E}
{5B89FD38-A096-4C9B-B39F-1FD6C591EE3D} = {D027D36B-262B-450A-B444-5B7893B5142E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BAD78470-3D66-466E-9C17-2A67F0905B18}

View file

@ -1,16 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="IdentityModel.AspNetCore.AccessTokenValidation" Version="1.0.0-preview.3" />
<PackageReference Include="IdentityModel.AspNetCore.OAuth2Introspection" Version="4.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="3.4.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="IdentityModel.AspNetCore.OAuth2Introspection" Version="4.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,57 @@
using System;
using System.Linq;
using Microsoft.AspNetCore.Http;
namespace ResourceBasedApi
{
/// <summary>
/// Provides helper functions for forwarding logic
/// </summary>
public static class Selector
{
/// <summary>
/// Provides a forwarding func for JWT vs reference tokens (based on existence of dot in token)
/// </summary>
/// <param name="introspectionScheme">Scheme name of the introspection handler</param>
/// <returns></returns>
public static Func<HttpContext, string> ForwardReferenceToken(string introspectionScheme = "introspection")
{
string Select(HttpContext context)
{
var (scheme, credential) = GetSchemeAndCredential(context);
if (scheme.Equals("Bearer", StringComparison.OrdinalIgnoreCase) &&
!credential.Contains("."))
{
return introspectionScheme;
}
return null;
}
return Select;
}
/// <summary>
/// Extracts scheme and credential from Authorization header (if present)
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public static (string, string) GetSchemeAndCredential(HttpContext context)
{
var header = context.Request.Headers["Authorization"].FirstOrDefault();
if (string.IsNullOrEmpty(header))
{
return ("", "");
}
var parts = header.Split(' ', StringSplitOptions.RemoveEmptyEntries);
if (parts.Length != 2)
{
return ("", "");
}
return (parts[0], parts[1]);
}
}
}

View file

@ -1,6 +1,5 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using IdentityModel.AspNetCore.AccessTokenValidation;
namespace ResourceBasedApi
{
@ -35,8 +34,6 @@ namespace ResourceBasedApi
options.ClientId = "urn:resource1";
options.ClientSecret = "secret";
});
services.AddScopeTransformation();
}
public void Configure(IApplicationBuilder app)

View file

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
@ -9,9 +9,8 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="3.4.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
</ItemGroup>
</Project>

View file

@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Constants\Constants.csproj" />
<ProjectReference Include="..\Constants\Constants.csproj"/>
</ItemGroup>

View file

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>

View file

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>

View file

@ -1,19 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<OutputType>Exe</OutputType>
<RootNamespace>ConsoleHybridWithPkce</RootNamespace>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.2.0" />
<PackageReference Include="IdentityModel.OidcClient" Version="4.0.0-preview.5" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
</ItemGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="IdentityModel.OidcClient" Version="5.0.0-preview.2" />
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Constants\Constants.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Constants\Constants.csproj"/>
</ItemGroup>
</Project>

View file

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>

View file

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>

View file

@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>

View file

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>

View file

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>

View file

@ -2,8 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>ConsoleStructuredScopeClient</RootNamespace>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>

View file

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>
@ -16,7 +16,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.8.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.10.0" />
</ItemGroup>
</Project>

View file

@ -1,17 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1"/>
<PackageReference Include="IdentityModel.OidcClient" Version="4.0.0-preview.7"/>
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1"/>
<FrameworkReference Include="Microsoft.AspNetCore.App"/>
<PackageReference Include="IdentityModel.OidcClient" Version="5.0.0-preview.2"/>
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0"/>
</ItemGroup>
<ItemGroup>

View file

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>

View file

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>

View file

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>

View file

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>

View file

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>

View file

@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Constants\Constants.csproj" />
<ProjectReference Include="..\Constants\Constants.csproj"/>
</ItemGroup>
</Project>

View file

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
</Project>

View file

@ -1,19 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="IdentityModel.AspNetCore" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="5.0.0"/>
<ItemGroup>
<PackageReference Include="IdentityModel.AspNetCore" Version="4.0.0"/>
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="6.0.0"/>
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0"/>
</ItemGroup>
<PackageReference Include="Serilog.AspNetCore" Version="3.4.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Constants\Constants.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Constants\Constants.csproj"/>
</ItemGroup>
</Project>

View file

@ -80,7 +80,7 @@ namespace MvcCode
services.AddAccessTokenManagement();
// add HTTP client to call protected API
services.AddUserAccessTokenClient("client", client =>
services.AddUserAccessTokenHttpClient("client", configureClient: client =>
{
client.BaseAddress = new Uri(Constants.SampleApi);
});

View file

@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="5.0.0" />
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="6.0.0"/>
<ProjectReference Include="..\Constants\Constants.csproj" />
</ItemGroup>
<ProjectReference Include="..\Constants\Constants.csproj"/>
</ItemGroup>
</Project>

View file

@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="5.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="6.0.0" />
<ProjectReference Include="..\Constants\Constants.csproj" />
</ItemGroup>

View file

@ -4,7 +4,9 @@ using IdentityModel.AspNetCore.AccessTokenManagement;
using IdentityModel.Client;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Serilog;
namespace MvcCode
{
@ -13,12 +15,14 @@ namespace MvcCode
private readonly AssertionService _assertionService;
public AssertionConfigurationService(
IOptions<AccessTokenManagementOptions> accessTokenManagementOptions,
UserAccessTokenManagementOptions userAccessTokenManagementOptions,
ClientAccessTokenManagementOptions clientAccessTokenManagementOptions,
IOptionsMonitor<OpenIdConnectOptions> oidcOptions,
IAuthenticationSchemeProvider schemeProvider,
AssertionService assertionService) : base(accessTokenManagementOptions,
oidcOptions,
schemeProvider)
AssertionService assertionService,
ILogger<AssertionConfigurationService> logger)
: base(userAccessTokenManagementOptions, clientAccessTokenManagementOptions, oidcOptions, schemeProvider, logger)
{
_assertionService = assertionService;
}

View file

@ -1,19 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="IdentityModel.AspNetCore" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="5.0.0" />
<ItemGroup>
<PackageReference Include="IdentityModel.AspNetCore" Version="4.0.0"/>
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="6.0.0"/>
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0"/>
</ItemGroup>
<PackageReference Include="Serilog.AspNetCore" Version="3.4.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Constants\Constants.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Constants\Constants.csproj"/>
</ItemGroup>
</Project>

View file

@ -13,8 +13,6 @@ namespace MvcCode
{
public void ConfigureServices(IServiceCollection services)
{
JwtSecurityTokenHandler.DefaultMapInboundClaims = false;
services.AddSingleton<AssertionService>();
services.AddTransient<OidcEvents>();
@ -60,6 +58,7 @@ namespace MvcCode
// keeps id_token smaller
options.GetClaimsFromUserInfoEndpoint = true;
options.SaveTokens = true;
options.MapInboundClaims = false;
// needed to add JWR / private_key_jwt support
options.EventsType = typeof(OidcEvents);
@ -76,7 +75,7 @@ namespace MvcCode
services.AddTransient<ITokenClientConfigurationService, AssertionConfigurationService>();
// add HTTP client to call protected API
services.AddUserAccessTokenClient("client", client =>
services.AddUserAccessTokenHttpClient("client", configureClient: client =>
{
client.BaseAddress = new Uri(Constants.SampleApi);
});

View file

@ -4,6 +4,7 @@ using IdentityModel.AspNetCore.AccessTokenManagement;
using IdentityModel.Client;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
namespace MvcCode
@ -13,12 +14,14 @@ namespace MvcCode
private readonly AssertionService _assertionService;
public AssertionConfigurationService(
IOptions<AccessTokenManagementOptions> accessTokenManagementOptions,
UserAccessTokenManagementOptions userAccessTokenManagementOptions,
ClientAccessTokenManagementOptions clientAccessTokenManagementOptions,
IOptionsMonitor<OpenIdConnectOptions> oidcOptions,
IAuthenticationSchemeProvider schemeProvider,
AssertionService assertionService) : base(accessTokenManagementOptions,
oidcOptions,
schemeProvider)
AssertionService assertionService,
ILogger<AssertionConfigurationService> logger)
: base(userAccessTokenManagementOptions, clientAccessTokenManagementOptions, oidcOptions, schemeProvider, logger)
{
_assertionService = assertionService;
}

View file

@ -1,15 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="IdentityModel.AspNetCore" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="5.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="3.4.0" />
<PackageReference Include="IdentityModel.AspNetCore" Version="4.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="6.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
</ItemGroup>
<ItemGroup>

View file

@ -77,7 +77,7 @@ namespace MvcCode
services.AddTransient<ITokenClientConfigurationService, AssertionConfigurationService>();
// add HTTP client to call protected API
services.AddUserAccessTokenClient("client", client =>
services.AddUserAccessTokenHttpClient("client", configureClient: client =>
{
client.BaseAddress = new Uri(Constants.SampleApi);
});