@@ -711,9 +711,7 @@ from server in code.AuthorizationServer
711711 var getAuthServerResponse = await _httpClient . GetAsync ( authServerUrl ) ;
712712
713713 if ( ! getAuthServerResponse . IsSuccessStatusCode )
714- throw new HttpRequestException (
715- $ "Failed to get authorization server metadata. Status Code is: { getAuthServerResponse . StatusCode } "
716- ) ;
714+ continue ;
717715
718716 var content = await getAuthServerResponse . Content . ReadAsStringAsync ( ) ;
719717
@@ -724,28 +722,37 @@ from server in code.AuthorizationServer
724722 authorizationServerMetadatas . Add ( authServer ) ;
725723 }
726724
727- if ( authorizationServerMetadatas . Count == 1 )
728- return authorizationServerMetadatas . First ( ) ;
729-
730725 return credentialOffer . Match (
731726 Some : offer =>
732727 {
733728 var credentialOfferAuthCodeGrantType = from grants in offer . Grants
734729 from code in grants . AuthorizationCode
735730 select code ;
736731
737- return credentialOfferAuthCodeGrantType . Match (
738- Some : code => authorizationServerMetadatas . Find ( authServer => authServer . SupportsAuthCodeFlow ) ??
739- throw new InvalidOperationException ( "No suitable Authorization Server found" ) ,
732+ return credentialOfferAuthCodeGrantType . Match (
733+ Some : code => code . AuthorizationServer . Match (
734+ Some : requestedAuthServer =>
735+ authorizationServerMetadatas . Find ( authServer =>
736+ authServer . Issuer == requestedAuthServer . ToString ( ) )
737+ ?? throw new InvalidOperationException ( "No suitable Authorization Server found" ) ,
738+ None : ( ) => authorizationServerMetadatas . Find ( authServer => authServer . SupportsAuthCodeFlow ) ??
739+ throw new InvalidOperationException ( "No suitable Authorization Server found" ) ) ,
740740 None : ( ) =>
741741 {
742742 var credentialOfferPreAuthGrantType = from grants in offer . Grants
743- from code in grants . AuthorizationCode
743+ from code in grants . PreAuthorizedCode
744744 select code ;
745745
746746 return credentialOfferPreAuthGrantType . Match (
747- Some : preAuth => authorizationServerMetadatas . Find ( authServer => authServer . SupportsPreAuthFlow )
748- ?? throw new InvalidOperationException ( "No suitable Authorization Server found" ) ,
747+ Some : preAuth =>
748+ {
749+ return preAuth . AuthorizationServer . Match (
750+ Some : requestedAuthServer =>
751+ authorizationServerMetadatas . Find ( authServer =>
752+ authServer . Issuer == requestedAuthServer . ToString ( ) )
753+ ?? throw new InvalidOperationException ( "No suitable Authorization Server found" ) ,
754+ None : ( ) => authorizationServerMetadatas . Find ( authServer => authServer . SupportsPreAuthFlow ) ) ;
755+ } ,
749756 None : ( ) => authorizationServerMetadatas . First ( ) ) ;
750757 } ) ;
751758 } ,
0 commit comments