66using System . Text . Json ;
77using System . Threading . Tasks ;
88using Serilog . Sinks . SystemConsole . Themes ;
9- using Microsoft . IdentityModel . Tokens ;
10- using IdentityModel ;
11- using System . Security . Cryptography ;
129using IdentityModel . DPoP ;
1310
1411namespace 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 } ;
0 commit comments