Skip to content

Commit ec33108

Browse files
RolandGuijtRoland Guijt
andauthored
Aspireize tokenexchange sample + update package references (#316)
* Aspireize tokenexchange sample + update package references * Fix slnx --------- Co-authored-by: Roland Guijt <roland.guijt@duendesoftware.com>
1 parent ddcc81b commit ec33108

21 files changed

Lines changed: 227 additions & 23 deletions

IdentityServer/v7/TokenExchange/Client/Client.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Duende.IdentityModel" Version="7.1.0" />
10+
<PackageReference Include="Duende.IdentityModel" Version="8.1.0" />
1111
</ItemGroup>
1212
</Project>

IdentityServer/v7/TokenExchange/Client/TokenResponseExtensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Duende Software. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4+
using System.Buffers.Text;
45
using System.Diagnostics;
56
using System.Text;
67
using System.Text.Json;
@@ -26,8 +27,8 @@ public static void Show(this TokenResponse response)
2627
var header = parts[0];
2728
var claims = parts[1];
2829

29-
Console.WriteLine(PrettyPrintJson(Encoding.UTF8.GetString(Base64Url.Decode(header))));
30-
Console.WriteLine(PrettyPrintJson(Encoding.UTF8.GetString(Base64Url.Decode(claims))));
30+
Console.WriteLine(PrettyPrintJson(Encoding.UTF8.GetString(Base64Url.DecodeFromChars(header))));
31+
Console.WriteLine(PrettyPrintJson(Encoding.UTF8.GetString(Base64Url.DecodeFromChars(claims))));
3132
}
3233
}
3334
else

IdentityServer/v7/TokenExchange/IdentityServerHost/IdentityServerHost.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
<ItemGroup>
99
<PackageReference Include="Duende.IdentityServer" Version="7.4.7" />
10-
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<ProjectReference Include="..\..\Aspire.ServiceDefaults\Aspire.ServiceDefaults.csproj" />
1114
</ItemGroup>
1215
</Project>

IdentityServer/v7/TokenExchange/IdentityServerHost/Program.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,12 @@
44

55
using IdentityServerHost;
66
using Microsoft.AspNetCore.DataProtection;
7-
using Serilog;
8-
using Serilog.Sinks.SystemConsole.Themes;
97

108
Console.Title = "IdentityServer";
119

12-
Log.Logger = new LoggerConfiguration()
13-
.MinimumLevel.Information()
14-
.Enrich.FromLogContext()
15-
.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}", theme: AnsiConsoleTheme.Code)
16-
.CreateLogger();
17-
1810
var builder = WebApplication.CreateBuilder(args);
1911

20-
builder.Services.AddSerilog();
12+
builder.AddServiceDefaults();
2113

2214
var idsvrBuilder = builder.Services.AddIdentityServer()
2315
.AddInMemoryApiScopes(Config.Scopes)
@@ -36,6 +28,8 @@
3628

3729
var app = builder.Build();
3830

31+
app.MapDefaultEndpoints();
32+
3933
app.UseDeveloperExceptionPage();
4034

4135
app.UseIdentityServer();
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
**Token Exchange Sample**
2+
 
3+
 This sample requires multiple projects to be run at once. That can easily be done by running the included Aspire AppHost. The Aspire dashboard will show the status of all running applications and show you the links to the running applications. Aspire will also collect the Open Telemetry data (logs, metrics, traces) and make it available on the dashboard.
4+
For the included console application please look at the output of your IDE to see the results.
5+
 
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var builder = DistributedApplication.CreateBuilder(args);
2+
3+
var idsrv = builder.AddProject<Projects.IdentityServerHost>("identityserverhost");
4+
builder.AddProject<Projects.Client>("client")
5+
.WaitFor(idsrv);
6+
7+
builder.Build().Run();
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"$schema": "https://json.schemastore.org/launchsettings.json",
3+
"profiles": {
4+
"https": {
5+
"commandName": "Project",
6+
"dotnetRunMessages": true,
7+
"launchBrowser": true,
8+
"applicationUrl": "https://localhost:17036;http://localhost:15277",
9+
"environmentVariables": {
10+
"ASPNETCORE_ENVIRONMENT": "Development",
11+
"DOTNET_ENVIRONMENT": "Development",
12+
"ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21012",
13+
"ASPIRE_DASHBOARD_MCP_ENDPOINT_URL": "https://localhost:23192",
14+
"ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22249"
15+
}
16+
},
17+
"http": {
18+
"commandName": "Project",
19+
"dotnetRunMessages": true,
20+
"launchBrowser": true,
21+
"applicationUrl": "http://localhost:15277",
22+
"environmentVariables": {
23+
"ASPNETCORE_ENVIRONMENT": "Development",
24+
"DOTNET_ENVIRONMENT": "Development",
25+
"ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19284",
26+
"ASPIRE_DASHBOARD_MCP_ENDPOINT_URL": "http://localhost:18147",
27+
"ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20272"
28+
}
29+
}
30+
}
31+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Aspire.AppHost.Sdk/13.2.1">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net10.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<UserSecretsId>7345a95a-3a14-4c9b-985a-1dac550f4368</UserSecretsId>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<ProjectReference Include="..\Client\Client.csproj" />
13+
<ProjectReference Include="..\IdentityServerHost\IdentityServerHost.csproj" />
14+
</ItemGroup>
15+
16+
</Project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
}
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning",
6+
"Aspire.Hosting.Dcp": "Warning"
7+
}
8+
}
9+
}

0 commit comments

Comments
 (0)