TestingCommons.Azure
1.0.3
dotnet add package TestingCommons.Azure --version 1.0.3
NuGet\Install-Package TestingCommons.Azure -Version 1.0.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TestingCommons.Azure" Version="1.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TestingCommons.Azure" Version="1.0.3" />
<PackageReference Include="TestingCommons.Azure" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TestingCommons.Azure --version 1.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: TestingCommons.Azure, 1.0.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TestingCommons.Azure@1.0.3
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TestingCommons.Azure&version=1.0.3
#tool nuget:?package=TestingCommons.Azure&version=1.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
TestingCommons.Azure
The Azure project provides authentication utilities for Azure Active Directory integration in testing scenarios. It simplifies the process of obtaining access tokens using client credentials flow.
Key Components
AzureAdAuthenticator
- Handles Azure AD authentication using client credentials flow
- Automatically manages token expiration and renewal
- Caches tokens until they expire to avoid unnecessary requests
- Uses
IDateTimeProviderfor testable time-based operations
AzureAdOptions
- Configuration class for Azure AD settings
- Includes: TenantId, ClientId, ClientSecret, Scope
- Automatically constructs the authority URL from TenantId
Dependency Injection Extensions
AddAzureAdAuthenticator()- Registers all required services- Automatically configures options from configuration section "AzureAd"
Usage Examples
Configuration (appsettings.json)
{
"AzureAd": {
"TenantId": "your-tenant-id",
"ClientId": "your-client-id",
"ClientSecret": "your-client-secret",
"Scope": ["https://graph.microsoft.com/.default"]
}
}
Service Registration
// In Program.cs or Startup.cs
services.AddAzureAdAuthenticator(configuration);
Using the Authenticator
public class MyTestService
{
private readonly AzureAdAuthenticator _authenticator;
public MyTestService(AzureAdAuthenticator authenticator)
{
_authenticator = authenticator;
}
public async Task<string> CallProtectedApiAsync()
{
// Get access token (automatically handles caching and renewal)
string accessToken = await _authenticator.GetAccessTokenAsync();
// Use token in HTTP requests
using var client = new HttpClient();
client.DefaultRequestHeaders.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", accessToken);
var response = await client.GetAsync("https://api.example.com/protected");
return await response.Content.ReadAsStringAsync();
}
}
Manual Configuration
// For scenarios where you need manual configuration
var options = Microsoft.Extensions.Options.Options.Create(new AzureAdOptions
{
TenantId = "your-tenant-id",
ClientId = "your-client-id",
ClientSecret = "your-client-secret",
Scope = new[] { "https://graph.microsoft.com/.default" }
});
var dateProvider = new UtcDateTimeProvider();
var authenticator = new AzureAdAuthenticator(options, dateProvider);
string token = await authenticator.GetAccessTokenAsync();
Key Features
- Token Caching: Automatically caches tokens and only renews when expired
- Testable: Uses
IDateTimeProviderfor mockable time operations - Configuration-Driven: Easy setup through appsettings.json
- Client Credentials Flow: Suitable for service-to-service authentication
- Dependency Injection Ready: Built with DI container in mind
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- Microsoft.Extensions.Options (>= 9.0.8)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 9.0.8)
- Microsoft.Identity.Client (>= 4.74.1)
- TestingCommons.Core (>= 1.0.3)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on TestingCommons.Azure:
| Package | Downloads |
|---|---|
|
TestingCommons.RestApiClient
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.