@@ -7,18 +7,15 @@ namespace ModelContextProtocol.Authentication;
77/// </summary>
88public class AuthorizationDelegatingHandler : DelegatingHandler
99{
10- private readonly IMcpAuthorizationProvider _tokenProvider ;
11- private readonly string _scheme ;
10+ private readonly IMcpAuthorizationProvider _authorizationProvider ;
1211
1312 /// <summary>
1413 /// Initializes a new instance of the <see cref="AuthorizationDelegatingHandler"/> class.
1514 /// </summary>
16- /// <param name="tokenProvider">The provider that supplies authentication tokens.</param>
17- /// <param name="scheme">The authentication scheme to use, e.g., "Bearer".</param>
18- public AuthorizationDelegatingHandler ( IMcpAuthorizationProvider tokenProvider , string scheme )
15+ /// <param name="authorizationProvider">The provider that supplies authentication tokens.</param>
16+ public AuthorizationDelegatingHandler ( IMcpAuthorizationProvider authorizationProvider )
1917 {
20- _tokenProvider = tokenProvider ?? throw new ArgumentNullException ( nameof ( tokenProvider ) ) ;
21- _scheme = scheme ?? throw new ArgumentNullException ( nameof ( scheme ) ) ;
18+ _authorizationProvider = authorizationProvider ?? throw new ArgumentNullException ( nameof ( authorizationProvider ) ) ;
2219 }
2320
2421 /// <summary>
@@ -39,7 +36,7 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
3936 if ( response . StatusCode == System . Net . HttpStatusCode . Unauthorized )
4037 {
4138 // Try to handle the unauthorized response
42- var handled = await _tokenProvider . HandleUnauthorizedResponseAsync (
39+ var handled = await _authorizationProvider . HandleUnauthorizedResponseAsync (
4340 response ,
4441 cancellationToken ) ;
4542
@@ -66,10 +63,10 @@ private async Task AddAuthorizationHeaderAsync(HttpRequestMessage request, Cance
6663 {
6764 if ( request . RequestUri != null )
6865 {
69- var token = await _tokenProvider . GetCredentialAsync ( request . RequestUri , cancellationToken ) ;
66+ var token = await _authorizationProvider . GetCredentialAsync ( request . RequestUri , cancellationToken ) ;
7067 if ( ! string . IsNullOrEmpty ( token ) )
7168 {
72- request . Headers . Authorization = new AuthenticationHeaderValue ( _scheme , token ) ;
69+ request . Headers . Authorization = new AuthenticationHeaderValue ( _authorizationProvider . AuthorizationScheme , token ) ;
7370 }
7471 }
7572 }
0 commit comments