@@ -27,6 +27,9 @@ public class BasicOAuthAuthorizationProvider : ITokenProvider
2727 // Lazy-initialized shared HttpClient for when no client is provided
2828 private static readonly Lazy < HttpClient > _defaultHttpClient = new ( ( ) => new HttpClient ( ) ) ;
2929
30+ // Cached JsonSerializerOptions to avoid recreating it for each deserialization
31+ private static readonly JsonSerializerOptions _jsonOptions = new ( ) { PropertyNameCaseInsensitive = true } ;
32+
3033 private TokenContainer ? _token ;
3134 private AuthorizationServerMetadata ? _authServerMetadata ;
3235
@@ -159,9 +162,17 @@ public BasicOAuthAuthorizationProvider(
159162 {
160163 var json = await response . Content . ReadAsStringAsync ( cancellationToken ) ;
161164 var metadata = JsonSerializer . Deserialize < AuthorizationServerMetadata > (
162- json , new JsonSerializerOptions { PropertyNameCaseInsensitive = true } ) ;
165+ json , _jsonOptions ) ;
163166
164- if ( metadata != null ) return metadata ;
167+ if ( metadata != null )
168+ {
169+ metadata . ResponseTypesSupported ??= [ "code" ] ;
170+ metadata . GrantTypesSupported ??= [ "authorization_code" , "refresh_token" ] ;
171+ metadata . TokenEndpointAuthMethodsSupported ??= [ "client_secret_basic" ] ;
172+ metadata . CodeChallengeMethodsSupported ??= [ "S256" ] ;
173+
174+ return metadata ;
175+ }
165176 }
166177 }
167178 catch ( Exception ex )
@@ -200,7 +211,7 @@ public BasicOAuthAuthorizationProvider(
200211 {
201212 var json = await response . Content . ReadAsStringAsync ( cancellationToken ) ;
202213 var tokenResponse = JsonSerializer . Deserialize < TokenContainer > (
203- json , new JsonSerializerOptions { PropertyNameCaseInsensitive = true } ) ;
214+ json , _jsonOptions ) ;
204215
205216 if ( tokenResponse != null )
206217 {
@@ -341,7 +352,7 @@ private Uri BuildAuthorizationUrl(AuthorizationServerMetadata authServerMetadata
341352 {
342353 var json = await response . Content . ReadAsStringAsync ( cancellationToken ) ;
343354 var tokenResponse = JsonSerializer . Deserialize < TokenContainer > (
344- json , new JsonSerializerOptions { PropertyNameCaseInsensitive = true } ) ;
355+ json , _jsonOptions ) ;
345356
346357 if ( tokenResponse != null )
347358 {
0 commit comments