11using Microsoft . Extensions . Logging ;
22using Microsoft . Extensions . Logging . Abstractions ;
3- using System . Collections . Specialized ;
43using System . Diagnostics . CodeAnalysis ;
54using System . Net . Http . Headers ;
65using System . Security . Cryptography ;
@@ -28,12 +27,12 @@ internal sealed partial class ClientOAuthProvider
2827 private readonly IDictionary < string , string > _additionalAuthorizationParameters ;
2928 private readonly Func < IReadOnlyList < Uri > , Uri ? > _authServerSelector ;
3029 private readonly AuthorizationRedirectDelegate _authorizationRedirectDelegate ;
31- private readonly DynamicClientRegistrationDelegate ? _dynamicClientRegistrationDelegate ;
3230
33- // _clientName, _clientUri, and _initialAccessToken is used for dynamic client registration (RFC 7591)
34- private readonly string ? _clientName ;
35- private readonly Uri ? _clientUri ;
36- private readonly string ? _initialAccessToken ;
31+ // _dcrClientName, _dcrClientUri, _dcrInitialAccessToken and _dcrResponseDelegate are used for dynamic client registration (RFC 7591)
32+ private readonly string ? _dcrClientName ;
33+ private readonly Uri ? _dcrClientUri ;
34+ private readonly string ? _dcrInitialAccessToken ;
35+ private readonly Func < DynamicClientRegistrationResponse , CancellationToken , Task > ? _dcrResponseDelegate ;
3736
3837 private readonly HttpClient _httpClient ;
3938 private readonly ILogger _logger ;
@@ -79,20 +78,10 @@ public ClientOAuthProvider(
7978 // Set up authorization URL handler (use default if not provided)
8079 _authorizationRedirectDelegate = options . AuthorizationRedirectDelegate ?? DefaultAuthorizationUrlHandler ;
8180
82- if ( string . IsNullOrEmpty ( _clientId ) )
83- {
84- if ( options . DynamicClientRegistration is null )
85- {
86- throw new ArgumentException ( "ClientOAuthOptions.DynamicClientRegistration must be configured when ClientId is not set." , nameof ( options ) ) ;
87- }
88-
89- _clientName = options . DynamicClientRegistration . ClientName ;
90- _clientUri = options . DynamicClientRegistration . ClientUri ;
91- _initialAccessToken = options . DynamicClientRegistration . InitialAccessToken ;
92-
93- // Set up dynamic client registration delegate
94- _dynamicClientRegistrationDelegate = options . DynamicClientRegistration . DynamicClientRegistrationDelegate ;
95- }
81+ _dcrClientName = options . DynamicClientRegistration ? . ClientName ;
82+ _dcrClientUri = options . DynamicClientRegistration ? . ClientUri ;
83+ _dcrInitialAccessToken = options . DynamicClientRegistration ? . InitialAccessToken ;
84+ _dcrResponseDelegate = options . DynamicClientRegistration ? . ResponseDelegate ;
9685 }
9786
9887 /// <summary>
@@ -463,8 +452,8 @@ private async Task PerformDynamicClientRegistrationAsync(
463452 GrantTypes = [ "authorization_code" , "refresh_token" ] ,
464453 ResponseTypes = [ "code" ] ,
465454 TokenEndpointAuthMethod = "client_secret_post" ,
466- ClientName = _clientName ,
467- ClientUri = _clientUri ? . ToString ( ) ,
455+ ClientName = _dcrClientName ,
456+ ClientUri = _dcrClientUri ? . ToString ( ) ,
468457 Scope = _scopes is not null ? string . Join ( " " , _scopes ) : null
469458 } ;
470459
@@ -476,9 +465,9 @@ private async Task PerformDynamicClientRegistrationAsync(
476465 Content = requestContent
477466 } ;
478467
479- if ( ! string . IsNullOrEmpty ( _initialAccessToken ) )
468+ if ( ! string . IsNullOrEmpty ( _dcrInitialAccessToken ) )
480469 {
481- request . Headers . Authorization = new AuthenticationHeaderValue ( BearerScheme , _initialAccessToken ) ;
470+ request . Headers . Authorization = new AuthenticationHeaderValue ( BearerScheme , _dcrInitialAccessToken ) ;
482471 }
483472
484473 using var httpResponse = await _httpClient . SendAsync ( request , cancellationToken ) . ConfigureAwait ( false ) ;
@@ -509,9 +498,9 @@ private async Task PerformDynamicClientRegistrationAsync(
509498
510499 LogDynamicClientRegistrationSuccessful ( _clientId ! ) ;
511500
512- if ( _dynamicClientRegistrationDelegate is not null )
501+ if ( _dcrResponseDelegate is not null )
513502 {
514- await _dynamicClientRegistrationDelegate ( registrationResponse , cancellationToken ) . ConfigureAwait ( false ) ;
503+ await _dcrResponseDelegate ( registrationResponse , cancellationToken ) . ConfigureAwait ( false ) ;
515504 }
516505 }
517506
0 commit comments