Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Commit 3c64bc4

Browse files
add demo client, simplify setup
1 parent 58afd31 commit 3c64bc4

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed

clients/ConsoleClientWithBrowserAndDPoP/Program.cs

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,17 @@
66
using System.Text.Json;
77
using System.Threading.Tasks;
88
using Serilog.Sinks.SystemConsole.Themes;
9-
using Microsoft.IdentityModel.Tokens;
10-
using IdentityModel;
11-
using System.Security.Cryptography;
129
using IdentityModel.DPoP;
1310

1411
namespace ConsoleClientWithBrowserAndDPoP
1512
{
1613
public class Program
1714
{
18-
//static string _api = "https://demo.duendesoftware.com/api/dpop/test";
19-
static string _api = "https://localhost:5002/api/dpop/test";
15+
static string _api = "https://demo.duendesoftware.com/api/dpop/test";
16+
//static string _api = "https://localhost:5002/api/dpop/test";
2017

21-
//static string authority = "https://demo.duendesoftware.com";
22-
static string authority = "https://localhost:5001";
18+
static string authority = "https://demo.duendesoftware.com";
19+
//static string authority = "https://localhost:5001";
2320

2421
static OidcClient _oidcClient;
2522
static HttpClient _apiClient = new HttpClient { BaseAddress = new Uri(_api) };
@@ -43,27 +40,19 @@ private static async Task SignIn()
4340
var browser = new SystemBrowser();
4441
string redirectUri = string.Format($"http://127.0.0.1:{browser.Port}");
4542

46-
var key = new RsaSecurityKey(RSA.Create(2048))
47-
{
48-
KeyId = CryptoRandom.CreateUniqueId(16, CryptoRandom.OutputFormat.Hex)
49-
};
50-
var jwk = JsonWebKeyConverter.ConvertFromRSASecurityKey(key);
51-
jwk.Alg = "RS256";
52-
var jwkJson = JsonSerializer.Serialize(jwk);
53-
var tokenDpopHandler = new ProofTokenMessageHandler(jwkJson, new SocketsHttpHandler());
54-
var apiDpopHandler = new ProofTokenMessageHandler(jwkJson, new SocketsHttpHandler());
43+
var proofKey = JsonWebKeys.CreateRsaJson();
44+
var tokenDpopHandler = new ProofTokenMessageHandler(proofKey, new SocketsHttpHandler());
45+
var apiDpopHandler = new ProofTokenMessageHandler(proofKey, new SocketsHttpHandler());
5546

5647
var options = new OidcClientOptions
5748
{
5849
Authority = authority,
59-
//ClientId = "interactive.public.short",
60-
ClientId = "dpop.native",
50+
ClientId = "native.dpop",
6151
RedirectUri = redirectUri,
6252
Scope = "openid profile api offline_access",
6353
FilterClaims = false,
64-
6554
Browser = browser,
66-
IdentityTokenValidator = new JwtHandlerIdentityTokenValidator(),
55+
6756
BackchannelHandler = tokenDpopHandler,
6857
RefreshTokenInnerHttpHandler = apiDpopHandler
6958
};

clients/ConsoleClientWithBrowserAndDPoP/SystemBrowser.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
using Microsoft.AspNetCore.Http;
55
using System;
66
using System.Diagnostics;
7-
using System.IO;
87
using System.Net;
98
using System.Net.Sockets;
109
using System.Runtime.InteropServices;
11-
using System.Text;
1210
using System.Threading;
1311
using System.Threading.Tasks;
1412

src/DPoP/JsonWebKeys.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Security.Cryptography;
6+
using System.Text.Json;
67
using Microsoft.IdentityModel.Tokens;
78

89
namespace IdentityModel.DPoP;
@@ -25,6 +26,14 @@ public static JsonWebKey CreateRsa(string algorithm = OidcConstants.Algorithms.A
2526
return jwk;
2627
}
2728

29+
/// <summary>
30+
/// Creates a new RSA JWK string.
31+
/// </summary>
32+
public static string CreateRsaJson(string algorithm = OidcConstants.Algorithms.Asymmetric.PS256)
33+
{
34+
return JsonSerializer.Serialize(CreateRsa(algorithm));
35+
}
36+
2837
/// <summary>
2938
/// Creates a new ECDSA JWK.
3039
/// </summary>
@@ -39,6 +48,14 @@ public static JsonWebKey CreateECDsa(string algorithm = OidcConstants.Algorithms
3948
return jwk;
4049
}
4150

51+
/// <summary>
52+
/// Creates a new ECDSA JWK string.
53+
/// </summary>
54+
public static string CreateECDsaJson(string algorithm = OidcConstants.Algorithms.Asymmetric.ES256)
55+
{
56+
return JsonSerializer.Serialize(CreateECDsa(algorithm));
57+
}
58+
4259
internal static string GetCurveNameFromSigningAlgorithm(string alg)
4360
{
4461
return alg switch

0 commit comments

Comments
 (0)