@@ -37,7 +37,8 @@ public override async Task<TResponse> UnaryServerHandler<TRequest, TResponse>(TR
3737 {
3838 try
3939 {
40- var attribute = ( CheckPolicyAttribute ) continuation . Method . GetCustomAttributes ( typeof ( CheckPolicyAttribute ) , false ) . FirstOrDefault ( ) ;
40+ var attribute = ( CheckPolicyAttribute ) continuation . Method
41+ . GetCustomAttributes ( typeof ( CheckPolicyAttribute ) , false ) . FirstOrDefault ( ) ;
4142 if ( attribute == null )
4243 {
4344 return await continuation ( request , context ) ;
@@ -54,10 +55,27 @@ public override async Task<TResponse> UnaryServerHandler<TRequest, TResponse>(TR
5455 }
5556
5657 var client = new HttpClient ( ) ;
58+
5759 var idpConfig = _config . GetSection ( "Idp" ) ;
58- var disco = await client . GetDiscoveryDocumentAsync ( idpConfig . GetValue < string > ( "Authority" ) ) ;
59- var keys = new List < SecurityKey > ( ) ;
60+ var discoveryRequest = new DiscoveryDocumentRequest
61+ {
62+ Address = idpConfig . GetValue < string > ( "Authority" ) ,
63+ Policy =
64+ {
65+ Authority = idpConfig . GetValue < string > ( "Authority" ) ,
66+ RequireHttps = false , // TODO: for demo only
67+ ValidateIssuerName = false , // TODO: for demo only
68+ }
69+ } ;
6070
71+ var disco = await client . GetDiscoveryDocumentAsync ( discoveryRequest ) ;
72+ if ( disco ? . KeySet == null )
73+ {
74+ throw new Exception (
75+ $ "Cannot discover IdpServer with Authority={ idpConfig . GetValue < string > ( "Authority" ) } and Audience={ idpConfig . GetValue < string > ( "Audience" ) } .") ;
76+ }
77+
78+ var keys = new List < SecurityKey > ( ) ;
6179 foreach ( var webKey in disco . KeySet . Keys )
6280 {
6381 var e = Base64Url . Decode ( webKey . E ) ;
@@ -94,7 +112,8 @@ public override async Task<TResponse> UnaryServerHandler<TRequest, TResponse>(TR
94112 throw new AuthenticationException ( "Cannot get authorization on the header." ) ;
95113 }
96114
97- var user = handler . ValidateToken ( userToken . TrimStart ( "Bearer" ) . TrimStart ( "bearer" ) . TrimStart ( " " ) , parameters , out _ ) ;
115+ var user = handler . ValidateToken ( userToken . TrimStart ( "Bearer" ) . TrimStart ( "bearer" ) . TrimStart ( " " ) ,
116+ parameters , out _ ) ;
98117
99118 if ( user == null )
100119 {
0 commit comments