1+ // See https://aka.ms/new-console-template for more information
2+ using SimpleIdServer . CredentialIssuer . Api . CredentialIssuer ;
3+ using System . Text . Json ;
4+ using System . Text . Json . Nodes ;
5+ using System . Web ;
6+ using static QRCoder . PayloadGenerator ;
7+
8+ using ( var httpClient = new HttpClient ( ) )
9+ {
10+ var openidCredentialIssuer = GetOpenidCredentialIssuer ( httpClient ) . Result ;
11+ var authorizationEndpoint = GetAuthorizationEndpoint ( httpClient , openidCredentialIssuer . AuthorizationServer ) . Result ;
12+ ExecuteAuthorizationRequest ( httpClient , authorizationEndpoint ) . Wait ( ) ;
13+ }
14+
15+ async Task < ESBICredentialIssuerResult > GetOpenidCredentialIssuer ( HttpClient httpClient )
16+ {
17+ var url = "https://api-conformance.ebsi.eu/conformance/v3/issuer-mock/.well-known/openid-credential-issuer" ;
18+ var requestMessage = new HttpRequestMessage ( HttpMethod . Get , url ) ;
19+ var httpResult = await httpClient . SendAsync ( requestMessage ) ;
20+ var json = await httpResult . Content . ReadAsStringAsync ( ) ;
21+ var openidCredentialIssuer = JsonSerializer . Deserialize < ESBICredentialIssuerResult > ( json ) ;
22+ return openidCredentialIssuer ;
23+ }
24+
25+ async Task < string > GetAuthorizationEndpoint ( HttpClient httpClient , string authUrl )
26+ {
27+ var requestMessage = new HttpRequestMessage ( HttpMethod . Get , $ "{ authUrl } /.well-known/openid-configuration") ;
28+ var httpResult = await httpClient . SendAsync ( requestMessage ) ;
29+ var json = await httpResult . Content . ReadAsStringAsync ( ) ;
30+ return JsonObject . Parse ( json ) [ "authorization_endpoint" ] . ToString ( ) ;
31+ }
32+
33+ async Task ExecuteAuthorizationRequest ( HttpClient httpClient , string url )
34+ {
35+ var uriBuilder = new UriBuilder ( url ) ;
36+ var dic = new Dictionary < string , string >
37+ {
38+ { "client_id" , "did:key:z2dmzD81cgPx8Vki7JbuuMmFYrWPgYoytykUZ3eyqht1j9KbpMAoXtZtunruYnM4gCV65AKAUX2AwEReRhEaf3BRQNJArZPwQdmf9ENZcF8VT13a58WsHeVjJtvAKKPYEibaEfdUxvU7sgxEUTJpjEkq6BJKrRV1JQ1CqhYvGbmJ1WyoUQ" } ,
39+ { "redirect_uri" , "http://localhost:5005" } ,
40+ { "scope" , "openid" } ,
41+ { "response_type" , "code" }
42+ } ;
43+ uriBuilder . Query = string . Join ( "&" , dic . Select ( kvp => $ "{ kvp . Key } ={ kvp . Value } ") ) ;
44+ var requestMessage = new HttpRequestMessage
45+ {
46+ RequestUri = uriBuilder . Uri
47+ } ;
48+ var httpResult = await httpClient . SendAsync ( requestMessage ) ;
49+ var result = httpResult . Headers . Location . AbsoluteUri ;
50+ var json = await httpResult . Content . ReadAsStringAsync ( ) ;
51+
52+ }
0 commit comments