Skip to content

Commit 1f59d96

Browse files
Add ConfigureAwait(false) to all async/await calls in library code
Co-authored-by: frasermolyneux <34033625+frasermolyneux@users.noreply.github.com>
1 parent 855c0b8 commit 1f59d96

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/MX.Api.Client/Auth/ApiTokenProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ public async Task<string> GetAccessTokenAsync(string audience, CancellationToken
8787
// Get new token
8888
try
8989
{
90-
var credential = await tokenCredentialProvider.GetTokenCredentialAsync(cancellationToken);
90+
var credential = await tokenCredentialProvider.GetTokenCredentialAsync(cancellationToken).ConfigureAwait(false);
9191
var tokenResult = await credential.GetTokenAsync(
9292
new TokenRequestContext(new[] { string.Format(DefaultScopeFormat, audience) }),
93-
cancellationToken);
93+
cancellationToken).ConfigureAwait(false);
9494

9595
// Cache token with buffer time
9696
var cacheOptions = new MemoryCacheEntryOptions

src/MX.Api.Client/BaseApi.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public async Task<RestRequest> CreateRequestAsync(string resource, Method method
145145
var request = new RestRequest(resource, method);
146146

147147
// Apply authentication based on the configured authentication type
148-
await ApplyAuthenticationAsync(request, cancellationToken);
148+
await ApplyAuthenticationAsync(request, cancellationToken).ConfigureAwait(false);
149149

150150
return request;
151151
}
@@ -174,7 +174,7 @@ private async Task ApplyAuthenticationAsync(RestRequest request, CancellationTok
174174
break;
175175

176176
case EntraIdAuthenticationOptions entraIdOptions:
177-
await ApplyEntraIdAuthenticationAsync(request, entraIdOptions, cancellationToken);
177+
await ApplyEntraIdAuthenticationAsync(request, entraIdOptions, cancellationToken).ConfigureAwait(false);
178178
break;
179179

180180
default:
@@ -223,7 +223,7 @@ private async Task ApplyEntraIdAuthenticationAsync(
223223
throw new InvalidOperationException("IApiTokenProvider not available for Entra ID authentication");
224224
}
225225

226-
string accessToken = await apiTokenProvider.GetAccessTokenAsync(options.ApiAudience, cancellationToken);
226+
string accessToken = await apiTokenProvider.GetAccessTokenAsync(options.ApiAudience, cancellationToken).ConfigureAwait(false);
227227
request.AddHeader(AuthorizationHeaderName, $"{BearerTokenPrefix}{accessToken}");
228228
logger.LogDebug("Added Entra ID token authentication for audience '{Audience}'", options.ApiAudience);
229229
}
@@ -253,8 +253,8 @@ public async Task<RestResponse> ExecuteAsync(RestRequest request, CancellationTo
253253
{
254254
// Execute the request with retry policy
255255
var response = await retryPolicy.ExecuteAsync(
256-
async (token) => await restClientService.ExecuteAsync(options.BaseUrl, request, token),
257-
cancellationToken);
256+
async (token) => await restClientService.ExecuteAsync(options.BaseUrl, request, token).ConfigureAwait(false),
257+
cancellationToken).ConfigureAwait(false);
258258

259259
// Ensure response is not null to prevent NullReferenceException
260260
if (response is null)

0 commit comments

Comments
 (0)