HaveIBeenPwned.Client.PollyExtensions
2.0.1
See the version list below for details.
dotnet add package HaveIBeenPwned.Client.PollyExtensions --version 2.0.1
NuGet\Install-Package HaveIBeenPwned.Client.PollyExtensions -Version 2.0.1
<PackageReference Include="HaveIBeenPwned.Client.PollyExtensions" Version="2.0.1" />
paket add HaveIBeenPwned.Client.PollyExtensions --version 2.0.1
#r "nuget: HaveIBeenPwned.Client.PollyExtensions, 2.0.1"
// Install HaveIBeenPwned.Client.PollyExtensions as a Cake Addin #addin nuget:?package=HaveIBeenPwned.Client.PollyExtensions&version=2.0.1 // Install HaveIBeenPwned.Client.PollyExtensions as a Cake Tool #tool nuget:?package=HaveIBeenPwned.Client.PollyExtensions&version=2.0.1
A .NET HTTP client for the "have i been pwned" API service from Troy Hunt. This library is comprised of three NuGet packages:
Consumers of the API can use the abstractions for the models returned from the API, while server APIs can consume and wrap the client.
Get started
Install from the .NET CLI:
dotnet add package HaveIBeenPwned.Client
Alternatively add manually to your consuming .csproj:
<PackageReference Include="HaveIBeenPwned.Client" Version="{VersionNumber}" />
Or, install using the NuGet Package Manager:
Install-Package HaveIBeenPwned.Client
Dependency injection
To add all of the services to the dependency injection container, call one of the AddPwnedServices
overloads. From Minimal APIs for example, with using a named configuration section:
builder.Services.AddPwnedServices(
builder.Configuration.GetSection(nameof(HibpOptions)));
From a ConfigureServices
method, with an IConfiguration
instance:
services.AddPwnedServices(options =>
{
options.ApiKey = _configuration["HibpOptions:ApiKey"];
options.UserAgent = _configuration["HibpOptions:UserAgent"];
});
Then you can require any of the available DI-ready types:
IPwnedBreachesClient
: Breaches API.IPwnedPastesClient
: Pastes API.IPwnedPasswordsClient
: Pwned Passwords API.IPwnedClient
: Marker interface, for conveniently injecting all of the above clients into a single client.
Example Minimal APIs
Configuration
To configure the HaveIBeenPwned.Client
, the following table identifies the well-known configuration object:
Well-known keys
Depending on the .NET configuration provider your app is using, there are several well-known keys that map to the HibpOptions
that configure your usage of the HTTP client. When using environment variables, such as those in Azure App Service configuration or Azure Key Vault secrets, the following keys map to the HibpOption
instance:
Key | Data type | Default value |
---|---|---|
HibpOptions__ApiKey |
string |
null |
HibpOptions__UserAgent |
string |
".NET HIBP Client/{AssemblyFileVersion}" |
The ApiKey
is required, to get one — sign up here: https://haveibeenpwned.com/api/key
Example appsettings.json
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"HibpOptions": {
"ApiKey": "<YourApiKey>",
"UserAgent": "<YourUserAgent>"
}
}
For more information, see JSON configuration provider.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
-
net6.0
- HaveIBeenPwned.Client (>= 2.0.1)
- Microsoft.Extensions.Http (>= 6.0.0)
- Microsoft.Extensions.Http.Polly (>= 6.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 6.0.0)
- System.Net.Http.Json (>= 6.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on HaveIBeenPwned.Client.PollyExtensions:
Repository | Stars |
---|---|
IEvangelist/learning-blazor
The application for the "Learning Blazor: Build Single Page Apps with WebAssembly and C#" O'Reilly Media book by David Pine.
|