Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/MX.Api.Client/Auth/ApiTokenProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ public async Task<string> GetAccessTokenAsync(string audience, CancellationToken
// Get new token
try
{
var credential = await tokenCredentialProvider.GetTokenCredentialAsync(cancellationToken);
var credential = await tokenCredentialProvider.GetTokenCredentialAsync(cancellationToken).ConfigureAwait(false);
var tokenResult = await credential.GetTokenAsync(
new TokenRequestContext(new[] { string.Format(DefaultScopeFormat, audience) }),
cancellationToken);
cancellationToken).ConfigureAwait(false);

// Cache token with buffer time
var cacheOptions = new MemoryCacheEntryOptions
Expand Down
10 changes: 5 additions & 5 deletions src/MX.Api.Client/BaseApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
private readonly TOptions options;
private readonly AsyncRetryPolicy<RestResponse> retryPolicy;

private static readonly HttpStatusCode[] SuccessStatusCodes = { HttpStatusCode.OK, HttpStatusCode.Created, HttpStatusCode.NoContent, HttpStatusCode.NotFound };

Check warning on line 30 in src/MX.Api.Client/BaseApi.cs

View workflow job for this annotation

GitHub Actions / quality / Code Quality

A static field in a generic type is not shared among instances of different close constructed types. (https://rules.sonarsource.com/csharp/RSPEC-2743)

Check warning on line 30 in src/MX.Api.Client/BaseApi.cs

View workflow job for this annotation

GitHub Actions / quality / Code Quality

A static field in a generic type is not shared among instances of different close constructed types. (https://rules.sonarsource.com/csharp/RSPEC-2743)
private static readonly HttpStatusCode[] NoRetryStatusCodes = { HttpStatusCode.OK, HttpStatusCode.Created, HttpStatusCode.NoContent, HttpStatusCode.NotFound, HttpStatusCode.Unauthorized, HttpStatusCode.BadRequest, HttpStatusCode.UnprocessableEntity };

Check warning on line 31 in src/MX.Api.Client/BaseApi.cs

View workflow job for this annotation

GitHub Actions / quality / Code Quality

A static field in a generic type is not shared among instances of different close constructed types. (https://rules.sonarsource.com/csharp/RSPEC-2743)

Check warning on line 31 in src/MX.Api.Client/BaseApi.cs

View workflow job for this annotation

GitHub Actions / quality / Code Quality

A static field in a generic type is not shared among instances of different close constructed types. (https://rules.sonarsource.com/csharp/RSPEC-2743)

/// <summary>
/// The strongly-typed options for this client
Expand Down Expand Up @@ -145,7 +145,7 @@
var request = new RestRequest(resource, method);

// Apply authentication based on the configured authentication type
await ApplyAuthenticationAsync(request, cancellationToken);
await ApplyAuthenticationAsync(request, cancellationToken).ConfigureAwait(false);

return request;
}
Expand Down Expand Up @@ -174,7 +174,7 @@
break;

case EntraIdAuthenticationOptions entraIdOptions:
await ApplyEntraIdAuthenticationAsync(request, entraIdOptions, cancellationToken);
await ApplyEntraIdAuthenticationAsync(request, entraIdOptions, cancellationToken).ConfigureAwait(false);
break;

default:
Expand Down Expand Up @@ -223,11 +223,11 @@
throw new InvalidOperationException("IApiTokenProvider not available for Entra ID authentication");
}

string accessToken = await apiTokenProvider.GetAccessTokenAsync(options.ApiAudience, cancellationToken);
string accessToken = await apiTokenProvider.GetAccessTokenAsync(options.ApiAudience, cancellationToken).ConfigureAwait(false);
request.AddHeader(AuthorizationHeaderName, $"{BearerTokenPrefix}{accessToken}");
logger.LogDebug("Added Entra ID token authentication for audience '{Audience}'", options.ApiAudience);
}
catch (AuthenticationException ex)

Check warning on line 230 in src/MX.Api.Client/BaseApi.cs

View workflow job for this annotation

GitHub Actions / quality / Code Quality

Either log this exception and handle it, or rethrow it with some contextual information. (https://rules.sonarsource.com/csharp/RSPEC-2139)

Check warning on line 230 in src/MX.Api.Client/BaseApi.cs

View workflow job for this annotation

GitHub Actions / quality / Code Quality

Either log this exception and handle it, or rethrow it with some contextual information. (https://rules.sonarsource.com/csharp/RSPEC-2139)
{
logger.LogError(ex, "Failed to get authentication token for audience '{Audience}'", options.ApiAudience);
throw;
Expand All @@ -253,8 +253,8 @@
{
// Execute the request with retry policy
var response = await retryPolicy.ExecuteAsync(
async (token) => await restClientService.ExecuteAsync(options.BaseUrl, request, token),
cancellationToken);
async (token) => await restClientService.ExecuteAsync(options.BaseUrl, request, token).ConfigureAwait(false),
cancellationToken).ConfigureAwait(false);

// Ensure response is not null to prevent NullReferenceException
if (response is null)
Expand All @@ -267,7 +267,7 @@
}
catch (OperationCanceledException)
{
logger.LogInformation("Request to '{Resource}' was canceled", request.Resource);

Check warning on line 270 in src/MX.Api.Client/BaseApi.cs

View workflow job for this annotation

GitHub Actions / quality / Code Quality

Logging in a catch clause should pass the caught exception as a parameter. (https://rules.sonarsource.com/csharp/RSPEC-6667)

Check warning on line 270 in src/MX.Api.Client/BaseApi.cs

View workflow job for this annotation

GitHub Actions / quality / Code Quality

Logging in a catch clause should pass the caught exception as a parameter. (https://rules.sonarsource.com/csharp/RSPEC-6667)
throw;
}
catch (HttpRequestException)
Expand All @@ -280,7 +280,7 @@
// Re-throw InvalidOperationException - already logged
throw;
}
catch (Exception ex)

Check warning on line 283 in src/MX.Api.Client/BaseApi.cs

View workflow job for this annotation

GitHub Actions / quality / Code Quality

Either log this exception and handle it, or rethrow it with some contextual information. (https://rules.sonarsource.com/csharp/RSPEC-2139)

Check warning on line 283 in src/MX.Api.Client/BaseApi.cs

View workflow job for this annotation

GitHub Actions / quality / Code Quality

Either log this exception and handle it, or rethrow it with some contextual information. (https://rules.sonarsource.com/csharp/RSPEC-2139)
{
logger.LogError(ex, "Unexpected error executing {Method} request to '{Resource}'",
request.Method, request.Resource);
Expand Down
Loading