@@ -38,8 +38,6 @@ internal class MicrosoftEntraAccessKey : IAccessKey
3838
3939 private static readonly TimeSpan GetAccessKeyIntervalWhenUnauthorized = TimeSpan . FromMinutes ( 5 ) ;
4040
41- private static readonly TimeSpan GetAccessKeyRetryInterval = TimeSpan . FromSeconds ( 3 ) ;
42-
4341 private readonly TaskCompletionSource < object ? > _initializedTcs = new TaskCompletionSource < object ? > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
4442
4543 private readonly IHttpClientFactory _httpClientFactory ;
@@ -48,6 +46,10 @@ internal class MicrosoftEntraAccessKey : IAccessKey
4846
4947 private DateTime _lastUpdatedTime = DateTime . MinValue ;
5048
49+ private volatile string ? _kid ;
50+
51+ private volatile byte [ ] ? _keyBytes ;
52+
5153 public bool IsAuthorized
5254 {
5355 get => _isAuthorized ;
@@ -66,23 +68,21 @@ private set
6668
6769 public TokenCredential TokenCredential { get ; }
6870
69- internal Exception ? LastException { get ; private set ; }
70-
71- internal string GetAccessKeyUrl { get ; }
71+ public string Kid => _kid ?? throw new ArgumentNullException ( nameof ( Kid ) ) ;
7272
73- internal bool HasExpired => DateTime . UtcNow - _lastUpdatedTime > TimeSpan . FromMinutes ( GetAccessKeyIntervalInMinute * 2 ) ;
73+ public byte [ ] KeyBytes => _keyBytes ?? throw new ArgumentNullException ( nameof ( KeyBytes ) ) ;
7474
75- private Task < object ? > InitializedTask => _initializedTcs . Task ;
75+ public Uri Endpoint { get ; }
7676
77- private volatile string ? _kid ;
77+ internal Exception ? LastException { get ; private set ; }
7878
79- private volatile byte [ ] ? _keyBytes ;
79+ internal string GetAccessKeyUrl { get ; }
8080
81- public string Kid => _kid ?? throw new ArgumentNullException ( nameof ( Kid ) ) ;
81+ internal bool HasExpired => DateTime . UtcNow - _lastUpdatedTime > TimeSpan . FromMinutes ( GetAccessKeyIntervalInMinute * 2 ) ;
8282
83- public byte [ ] KeyBytes => _keyBytes ?? throw new ArgumentNullException ( nameof ( KeyBytes ) ) ;
83+ internal TimeSpan GetAccessKeyRetryInterval { get ; set ; } = TimeSpan . FromSeconds ( 3 ) ;
8484
85- public Uri Endpoint { get ; }
85+ private Task < object ? > InitializedTask => _initializedTcs . Task ;
8686
8787 public MicrosoftEntraAccessKey ( Uri endpoint ,
8888 TokenCredential credential ,
@@ -189,7 +189,7 @@ internal async Task UpdateAccessKeyAsync(CancellationToken ctoken = default)
189189 IsAuthorized = false ;
190190 }
191191
192- private static async Task ThrowExceptionOnResponseFailureAsync ( HttpResponseMessage response )
192+ private static async Task ThrowExceptionOnResponseFailureAsync ( HttpRequestMessage request , HttpResponseMessage response )
193193 {
194194 if ( response . IsSuccessStatusCode )
195195 {
@@ -208,11 +208,12 @@ private static async Task ThrowExceptionOnResponseFailureAsync(HttpResponseMessa
208208 $ "Response status code does not indicate success: { ( int ) response . StatusCode } ({ response . ReasonPhrase } )") ;
209209#endif
210210
211- var requestUri = response . RequestMessage ? . RequestUri ? . ToString ( ) ;
211+ var requestUri = request . RequestUri ? . ToString ( ) ;
212+ var jwtToken = request . Headers . Authorization ? . Parameter ?? null ;
212213 throw response . StatusCode switch
213214 {
214215 HttpStatusCode . BadRequest => new AzureSignalRInvalidArgumentException ( requestUri , innerException , content ) ,
215- HttpStatusCode . Unauthorized => new AzureSignalRUnauthorizedException ( requestUri , innerException ) ,
216+ HttpStatusCode . Unauthorized => new AzureSignalRUnauthorizedException ( requestUri , innerException , jwtToken ) ,
216217 HttpStatusCode . NotFound => new AzureSignalRInaccessibleEndpointException ( requestUri , innerException ) ,
217218 _ => new AzureSignalRRuntimeException ( requestUri , innerException , response . StatusCode , content ) ,
218219 } ;
@@ -231,7 +232,7 @@ private async Task UpdateAccessKeyInternalAsync(CancellationToken ctoken)
231232
232233 await HandleHttpResponseAsync ( response ) ;
233234
234- await ThrowExceptionOnResponseFailureAsync ( response ) ;
235+ await ThrowExceptionOnResponseFailureAsync ( request , response ) ;
235236 }
236237
237238 private async Task < bool > HandleHttpResponseAsync ( HttpResponseMessage response )
0 commit comments