66using System . Diagnostics ;
77using System . Globalization ;
88using System . Linq ;
9+ using System . Runtime . ConstrainedExecution ;
910using System . Text ;
1011using System . Threading ;
1112using System . Threading . Tasks ;
1213using Microsoft . Identity . Client . ApiConfig . Parameters ;
14+ using Microsoft . Identity . Client . AuthScheme ;
1315using Microsoft . Identity . Client . Cache ;
1416using Microsoft . Identity . Client . Cache . Items ;
1517using Microsoft . Identity . Client . Core ;
1618using Microsoft . Identity . Client . Instance . Discovery ;
19+ using Microsoft . Identity . Client . Internal . Broker ;
1720using Microsoft . Identity . Client . OAuth2 ;
21+ using Microsoft . Identity . Client . TelemetryCore ;
1822using Microsoft . Identity . Client . TelemetryCore . Internal . Events ;
23+ using Microsoft . Identity . Client . TelemetryCore . OpenTelemetry ;
24+ using Microsoft . Identity . Client . TelemetryCore . TelemetryClient ;
1925using Microsoft . Identity . Client . Utils ;
20- using Microsoft . Identity . Client . TelemetryCore ;
2126using Microsoft . IdentityModel . Abstractions ;
22- using Microsoft . Identity . Client . TelemetryCore . TelemetryClient ;
23- using Microsoft . Identity . Client . TelemetryCore . OpenTelemetry ;
24- using Microsoft . Identity . Client . Internal . Broker ;
25- using System . Runtime . ConstrainedExecution ;
26- using Microsoft . Identity . Client . AuthScheme ;
2727
2828namespace Microsoft . Identity . Client . Internal . Requests
2929{
@@ -73,7 +73,7 @@ public async Task<AuthenticationResult> RunAsync(CancellationToken cancellationT
7373 {
7474 ApiEvent apiEvent = null ;
7575
76- var measureTelemetryDurationResult = StopwatchService . MeasureCodeBlock ( ( ) =>
76+ MeasureDurationResult measureTelemetryDurationResult = StopwatchService . MeasureCodeBlock ( ( ) =>
7777 {
7878 apiEvent = InitializeApiEvent ( AuthenticationRequestParameters . Account ? . HomeAccountId ? . Identifier ) ;
7979 AuthenticationRequestParameters . RequestContext . ApiEvent = apiEvent ;
@@ -82,7 +82,7 @@ public async Task<AuthenticationResult> RunAsync(CancellationToken cancellationT
8282 try
8383 {
8484 AuthenticationResult authenticationResult = null ;
85- var measureDurationResult = await StopwatchService . MeasureCodeBlockAsync ( async ( ) =>
85+ MeasureDurationResult measureDurationResult = await StopwatchService . MeasureCodeBlockAsync ( async ( ) =>
8686 {
8787 AuthenticationRequestParameters . LogParameters ( ) ;
8888 LogRequestStarted ( AuthenticationRequestParameters ) ;
@@ -156,10 +156,10 @@ private Tuple<string, string> ParseScopesForTelemetry()
156156
157157 if ( Uri . IsWellFormedUriString ( firstScope , UriKind . Absolute ) )
158158 {
159- Uri firstScopeAsUri = new Uri ( firstScope ) ;
159+ Uri firstScopeAsUri = new ( firstScope ) ;
160160 resource = $ "{ firstScopeAsUri . Scheme } ://{ firstScopeAsUri . Host } ";
161161
162- StringBuilder stringBuilder = new StringBuilder ( ) ;
162+ StringBuilder stringBuilder = new ( ) ;
163163
164164 foreach ( string scope in AuthenticationRequestParameters . Scope )
165165 {
@@ -199,7 +199,7 @@ private static void LogMetricsFromAuthResult(AuthenticationResult authentication
199199 {
200200 if ( logger . IsLoggingEnabled ( LogLevel . Always ) )
201201 {
202- var metadata = authenticationResult . AuthenticationResultMetadata ;
202+ AuthenticationResultMetadata metadata = authenticationResult . AuthenticationResultMetadata ;
203203 logger . Always (
204204 $ """
205205
@@ -237,7 +237,7 @@ protected virtual void EnrichTelemetryApiEvent(ApiEvent apiEvent)
237237 private ApiEvent InitializeApiEvent ( string accountId )
238238#pragma warning restore IDE0060
239239 {
240- ApiEvent apiEvent = new ApiEvent ( AuthenticationRequestParameters . RequestContext . CorrelationId )
240+ ApiEvent apiEvent = new ( AuthenticationRequestParameters . RequestContext . CorrelationId )
241241 {
242242 ApiId = AuthenticationRequestParameters . ApiId ,
243243 IsTokenCacheSerialized =
@@ -268,11 +268,9 @@ private ApiEvent InitializeApiEvent(string accountId)
268268
269269 private void UpdateCallerSdkDetails ( ApiEvent apiEvent )
270270 {
271- string callerSdkId ;
272- string callerSdkVer ;
273271
274272 // Check if ExtraQueryParameters contains caller-sdk-id and caller-sdk-ver
275- if ( AuthenticationRequestParameters . ExtraQueryParameters . TryGetValue ( Constants . CallerSdkIdKey , out callerSdkId ) )
273+ if ( AuthenticationRequestParameters . ExtraQueryParameters . TryGetValue ( Constants . CallerSdkIdKey , out string callerSdkId ) )
276274 {
277275 AuthenticationRequestParameters . ExtraQueryParameters . Remove ( Constants . CallerSdkIdKey ) ;
278276 }
@@ -281,7 +279,7 @@ private void UpdateCallerSdkDetails(ApiEvent apiEvent)
281279 callerSdkId = AuthenticationRequestParameters . RequestContext . ServiceBundle . Config . ClientName ;
282280 }
283281
284- if ( AuthenticationRequestParameters . ExtraQueryParameters . TryGetValue ( Constants . CallerSdkVersionKey , out callerSdkVer ) )
282+ if ( AuthenticationRequestParameters . ExtraQueryParameters . TryGetValue ( Constants . CallerSdkVersionKey , out string callerSdkVer ) )
285283 {
286284 AuthenticationRequestParameters . ExtraQueryParameters . Remove ( Constants . CallerSdkVersionKey ) ;
287285 }
@@ -331,7 +329,7 @@ protected async Task<AuthenticationResult> CacheTokenResponseAndCreateAuthentica
331329 AuthenticationRequestParameters . ApiId != ApiEvent . ApiIds . AcquireTokenForUserAssignedManagedIdentity &&
332330 AuthenticationRequestParameters . ApiId != ApiEvent . ApiIds . AcquireTokenByRefreshToken &&
333331 AuthenticationRequestParameters . AuthorityInfo . AuthorityType != AuthorityType . Adfs &&
334- ! ( msalTokenResponse . ClientInfo is null ) )
332+ msalTokenResponse . ClientInfo is not null )
335333 {
336334 //client_info is not returned from managed identity flows because there is no user present.
337335 clientInfoFromServer = ClientInfo . CreateFromJson ( msalTokenResponse . ClientInfo ) ;
@@ -340,9 +338,9 @@ protected async Task<AuthenticationResult> CacheTokenResponseAndCreateAuthentica
340338
341339 AuthenticationRequestParameters . RequestContext . Logger . Info ( "Saving token response to cache.." ) ;
342340
343- var tuple = await CacheManager . SaveTokenResponseAsync ( msalTokenResponse ) . ConfigureAwait ( false ) ;
344- var atItem = tuple . Item1 ;
345- var idtItem = tuple . Item2 ;
341+ Tuple < MsalAccessTokenCacheItem , MsalIdTokenCacheItem , Account > tuple = await CacheManager . SaveTokenResponseAsync ( msalTokenResponse ) . ConfigureAwait ( false ) ;
342+ MsalAccessTokenCacheItem atItem = tuple . Item1 ;
343+ MsalIdTokenCacheItem idtItem = tuple . Item2 ;
346344 Account account = tuple . Item3 ;
347345#if ! MOBILE
348346 atItem ? . AddAdditionalCacheParameters ( clientInfoFromServer ? . AdditionalResponseParameters ) ;
@@ -376,7 +374,7 @@ internal async Task<MsalTokenResponse> SendTokenRequestAsync(
376374 {
377375 var tokenEndpoint = await AuthenticationRequestParameters . Authority . GetTokenEndpointAsync ( AuthenticationRequestParameters . RequestContext ) . ConfigureAwait ( false ) ;
378376
379- var tokenResponse = await SendTokenRequestAsync (
377+ MsalTokenResponse tokenResponse = await SendTokenRequestAsync (
380378 tokenEndpoint ,
381379 additionalBodyParameters ,
382380 cancellationToken ) . ConfigureAwait ( false ) ;
@@ -393,7 +391,7 @@ protected Task<MsalTokenResponse> SendTokenRequestAsync(
393391 string scopes = GetOverriddenScopes ( AuthenticationRequestParameters . Scope ) . AsSingleString ( ) ;
394392 var tokenClient = new TokenClient ( AuthenticationRequestParameters ) ;
395393
396- var CcsHeader = GetCcsHeader ( additionalBodyParameters ) ;
394+ KeyValuePair < string , string > ? CcsHeader = GetCcsHeader ( additionalBodyParameters ) ;
397395 if ( CcsHeader != null && ! string . IsNullOrEmpty ( CcsHeader . Value . Key ) )
398396 {
399397 tokenClient . AddHeaderToClient ( CcsHeader . Value . Key , CcsHeader . Value . Value ) ;
@@ -417,7 +415,7 @@ private void InjectPcaSsoPolicyHeader(TokenClient tokenClient)
417415 ServiceBundle . Config ,
418416 AuthenticationRequestParameters . RequestContext . Logger ) ;
419417
420- var ssoPolicyHeaders = broker . GetSsoPolicyHeaders ( ) ;
418+ IReadOnlyDictionary < string , string > ssoPolicyHeaders = broker . GetSsoPolicyHeaders ( ) ;
421419 foreach ( KeyValuePair < string , string > kvp in ssoPolicyHeaders )
422420 {
423421 tokenClient . AddHeaderToClient ( kvp . Key , kvp . Value ) ;
@@ -531,16 +529,16 @@ internal async Task<AuthenticationResult> HandleTokenRefreshErrorAsync(
531529 MsalAccessTokenCacheItem cachedAccessTokenItem ,
532530 CancellationToken cancellationToken )
533531 {
534- var logger = AuthenticationRequestParameters . RequestContext . Logger ;
532+ ILoggerAdapter logger = AuthenticationRequestParameters . RequestContext . Logger ;
535533
536534 logger . Warning ( $ "Fetching a new AT failed. Is exception retry-able? { e . IsRetryable } . Is there an AT in the cache that is usable? { cachedAccessTokenItem != null } ") ;
537535
538536 if ( cachedAccessTokenItem != null && e . IsRetryable )
539537 {
540538 logger . Info ( "Returning existing access token. It is not expired, but should be refreshed. " ) ;
541539
542- var idToken = await CacheManager . GetIdTokenCacheItemAsync ( cachedAccessTokenItem ) . ConfigureAwait ( false ) ;
543- var account = await CacheManager . GetAccountAssociatedWithAccessTokenAsync ( cachedAccessTokenItem ) . ConfigureAwait ( false ) ;
540+ MsalIdTokenCacheItem idToken = await CacheManager . GetIdTokenCacheItemAsync ( cachedAccessTokenItem ) . ConfigureAwait ( false ) ;
541+ Account account = await CacheManager . GetAccountAssociatedWithAccessTokenAsync ( cachedAccessTokenItem ) . ConfigureAwait ( false ) ;
544542
545543 return await AuthenticationResult . CreateAsync (
546544 cachedAccessTokenItem ,
0 commit comments