@@ -711,9 +711,7 @@ from server in code.AuthorizationServer
711
711
var getAuthServerResponse = await _httpClient . GetAsync ( authServerUrl ) ;
712
712
713
713
if ( ! getAuthServerResponse . IsSuccessStatusCode )
714
- throw new HttpRequestException (
715
- $ "Failed to get authorization server metadata. Status Code is: { getAuthServerResponse . StatusCode } "
716
- ) ;
714
+ continue ;
717
715
718
716
var content = await getAuthServerResponse . Content . ReadAsStringAsync ( ) ;
719
717
@@ -724,28 +722,37 @@ from server in code.AuthorizationServer
724
722
authorizationServerMetadatas . Add ( authServer ) ;
725
723
}
726
724
727
- if ( authorizationServerMetadatas . Count == 1 )
728
- return authorizationServerMetadatas . First ( ) ;
729
-
730
725
return credentialOffer . Match (
731
726
Some : offer =>
732
727
{
733
728
var credentialOfferAuthCodeGrantType = from grants in offer . Grants
734
729
from code in grants . AuthorizationCode
735
730
select code ;
736
731
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" ) ) ,
740
740
None : ( ) =>
741
741
{
742
742
var credentialOfferPreAuthGrantType = from grants in offer . Grants
743
- from code in grants . AuthorizationCode
743
+ from code in grants . PreAuthorizedCode
744
744
select code ;
745
745
746
746
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
+ } ,
749
756
None : ( ) => authorizationServerMetadatas . First ( ) ) ;
750
757
} ) ;
751
758
} ,
0 commit comments