Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ievangelist/pwned-client
A .NET 8.0 HTTP client library for the "';-- Have I Been Pwned" API: https://haveibeenpwned.com/api/v3
https://github.com/ievangelist/pwned-client
csharp dependency-injection dotnet hacktoberfest hibp hibp-api hibpwned http-client pwned pwned-api pwned-passwords pwnedpasswords
Last synced: 7 days ago
JSON representation
A .NET 8.0 HTTP client library for the "';-- Have I Been Pwned" API: https://haveibeenpwned.com/api/v3
- Host: GitHub
- URL: https://github.com/ievangelist/pwned-client
- Owner: IEvangelist
- License: mit
- Created: 2021-08-31T01:46:35.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-25T11:10:08.000Z (13 days ago)
- Last Synced: 2024-10-29T20:08:26.209Z (9 days ago)
- Topics: csharp, dependency-injection, dotnet, hacktoberfest, hibp, hibp-api, hibpwned, http-client, pwned, pwned-api, pwned-passwords, pwnedpasswords
- Language: C#
- Homepage:
- Size: 1.94 MB
- Stars: 34
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# ![';-- have i been pwned? — .NET HTTP client.](https://raw.githubusercontent.com/IEvangelist/pwned-client/main/assets/pwned-header.png)
[![build](https://github.com/IEvangelist/pwned-client/actions/workflows/build-validation.yml/badge.svg)](https://github.com/IEvangelist/pwned-client/actions/workflows/build-validation.yml) [![code analysis](https://github.com/IEvangelist/pwned-client/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/IEvangelist/pwned-client/actions/workflows/codeql-analysis.yml) [![NuGet](https://img.shields.io/nuget/v/HaveIBeenPwned.Client.svg?style=flat)](https://www.nuget.org/packages/HaveIBeenPwned.Client) ![nuget downloads](https://img.shields.io/nuget/dt/HaveIBeenPwned.Client?color=blue&label=nuget%20downloads&logo=nuget)
`HaveIBeenPwned.Client` is a .NET HTTP client for the "have i been pwned" API service from Troy Hunt. This library is comprised of three NuGet packages:
- [`HaveIBeenPwned.Client`](https://www.nuget.org/packages/HaveIBeenPwned.Client)
- [`HaveIBeenPwned.Client.Abstractions`](https://www.nuget.org/packages/HaveIBeenPwned.Client.Abstractions)
- [`HaveIBeenPwned.Client.PollyExtensions`](https://www.nuget.org/packages/HaveIBeenPwned.Client.PollyExtensions)> Consumers of the API can use the abstractions for the models returned from the API, while server APIs can consume and wrap the client.
## Getting started
Install from the .NET CLI:
```shell
dotnet add package HaveIBeenPwned.Client
```Alternatively add manually to your consuming _.csproj_:
```xml
```
Or, install using the NuGet Package Manager:
```powershell
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:
```csharp
builder.Services.AddPwnedServices(
builder.Configuration.GetSection(nameof(HibpOptions)));
```From a `ConfigureServices` method, with an `IConfiguration` instance:
```csharp
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](https://haveibeenpwned.com/API/v3#BreachesForAccount).
- `IPwnedPastesClient`: [Pastes API](https://haveibeenpwned.com/API/v3#PastesForAccount).
- `IPwnedPasswordsClient`: [Pwned Passwords API](https://haveibeenpwned.com/API/v3#PwnedPasswords).
- `IPwnedClient`: Marker interface, for conveniently injecting all of the above clients into a single client.### Without dependency injection
If you're not using the DI approach, simply instaniate `PwnedClient` with your API key and use it as you see fit.
```csharp
IPwnedClient client = new PwnedClient("");
// TODO: Use client...
```### Example Minimal APIs
![Minimal APIs example code.](https://raw.githubusercontent.com/IEvangelist/pwned-client/main/assets/minimal-api.svg)
## Configuration
To configure the `HaveIBeenPwned.Client`, the following table identifies the well-known configuration object:
### Well-known keys
Depending on the [.NET configuration provider](https://docs.microsoft.com/dotnet/core/extensions/configuration-providers?WC.m_id=dapine) 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:
### Example `appsettings.json`
```json
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"HibpOptions": {
"ApiKey": "",
"UserAgent": ""
}
}
```For more information, see [JSON configuration provider](https://docs.microsoft.com/dotnet/core/extensions/configuration-providers?WC.m_id=dapine#json-configuration-provider).