Code Monkey home page Code Monkey logo

pwned-client's Introduction

';-- have i been pwned? โ€” .NET HTTP client.

build code analysis NuGet nuget downloads

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:

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:

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.

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.

IPwnedClient client = new PwnedClient("<API Key>");
// TODO: Use client...

Example Minimal APIs

Minimal APIs example code.

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.

pwned-client's People

Contributors

benomine avatar davidfowl avatar ievangelist avatar imgbot[bot] avatar weihanli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.