-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
01717e8
commit a585a73
Showing
22 changed files
with
851 additions
and
849 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,44 @@ | ||
// Copyright (c) David Pine. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
builder.Services.AddPwnedServices( | ||
builder.Configuration.GetSection(nameof(HibpOptions))); | ||
|
||
builder.Services.AddEndpointsApiExplorer(); | ||
builder.Services.AddSwaggerGen(options => | ||
options.SwaggerDoc("v1", new() { Title = "HaveIBeenPwned.MinimalApi", Version = "v1" })); | ||
|
||
using var app = builder.Build(); | ||
|
||
if (builder.Environment.IsDevelopment()) | ||
{ | ||
app.UseDeveloperExceptionPage(); | ||
app.UseSwagger(); | ||
app.UseSwaggerUI(options => | ||
options.SwaggerEndpoint("/swagger/v1/swagger.json", "HaveIBeenPwned.MinimalApi v1")); | ||
} | ||
|
||
app.UseHttpsRedirection(); | ||
|
||
// Map "have i been pwned" breaches. | ||
app.MapGroup("api/breaches") | ||
.MapPwnedBreachesApi(); | ||
|
||
// Map "have i been pwned" passwords. | ||
app.MapGet("api/passwords/{plainTextPassword}", | ||
(string plainTextPassword, IPwnedPasswordsClient client) => client.GetPwnedPasswordAsync(plainTextPassword)); | ||
|
||
// Map "have i been pwned" pastes. | ||
app.MapGet("api/pastes/{account}", | ||
(string account, IPwnedPastesClient client) => client.GetPastesAsync(account)); | ||
|
||
await app.RunAsync(); | ||
// Copyright (c) David Pine. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
builder.Services.AddPwnedServices( | ||
builder.Configuration.GetSection(nameof(HibpOptions))); | ||
|
||
builder.Services.AddEndpointsApiExplorer(); | ||
builder.Services.AddSwaggerGen(options => | ||
options.SwaggerDoc("v1", new() | ||
{ | ||
Title = "HaveIBeenPwned.MinimalApi", | ||
Version = "v1" | ||
})); | ||
|
||
using var app = builder.Build(); | ||
|
||
if (builder.Environment.IsDevelopment()) | ||
{ | ||
app.UseDeveloperExceptionPage(); | ||
app.UseSwagger(); | ||
app.UseSwaggerUI(options => | ||
options.SwaggerEndpoint( | ||
"/swagger/v1/swagger.json", "HaveIBeenPwned.MinimalApi v1")); | ||
} | ||
|
||
app.UseHttpsRedirection(); | ||
|
||
// Map "have i been pwned" breaches. | ||
app.MapGroup("api/breaches") | ||
.MapPwnedBreachesApi(); | ||
|
||
// Map "have i been pwned" passwords. | ||
app.MapGet("api/passwords/{plainTextPassword}", | ||
static (string plainTextPassword, IPwnedPasswordsClient client) => | ||
client.GetPwnedPasswordAsync(plainTextPassword)); | ||
|
||
// Map "have i been pwned" pastes. | ||
app.MapGet("api/pastes/{account}", | ||
static (string account, IPwnedPastesClient client) => | ||
client.GetPastesAsync(account)); | ||
|
||
await app.RunAsync(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
// Copyright (c) David Pine. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
global using System.Text.Json; | ||
global using System.Text.Json.Serialization; | ||
|
||
global using HaveIBeenPwned.Client.Abstractions; |
12 changes: 6 additions & 6 deletions
12
src/HaveIBeenPwned.Client.Abstractions/Internals/Visibility.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
// Copyright (c) David Pine. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: InternalsVisibleTo("HaveIBeenPwned.Client")] | ||
// Copyright (c) David Pine. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: InternalsVisibleTo("HaveIBeenPwned.Client")] | ||
[assembly: InternalsVisibleTo("HaveIBeenPwned.Client.AbstractionsTests")] |
160 changes: 80 additions & 80 deletions
160
src/HaveIBeenPwned.Client.Abstractions/Models/BreachDetails.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,80 @@ | ||
// Copyright (c) David Pine. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace HaveIBeenPwned.Client.Abstractions; | ||
|
||
/// <summary> | ||
/// See <a href="https://haveibeenpwned.com/api/v3#BreachModel"></a> | ||
/// </summary> | ||
public sealed class BreachDetails : BreachHeader | ||
{ | ||
/// <summary> | ||
/// A descriptive title for the breach suitable for displaying to end users. It's unique across all breaches but individual values may change in the future (i.e. if another breach occurs against an organisation already in the system). If a stable value is required to reference the breach, refer to the "Name" attribute instead. | ||
/// </summary> | ||
public string Title { get; set; } = null!; | ||
|
||
/// <summary> | ||
/// The domain of the primary website the breach occurred on. This may be used for identifying other assets external systems may have for the site. | ||
/// </summary> | ||
public string Domain { get; set; } = null!; | ||
|
||
/// <summary> | ||
/// The date (with no time) the breach originally occurred on in ISO 8601 format. This is not always accurate — frequently breaches are discovered and reported long after the original incident. Use this attribute as a guide only. | ||
/// </summary> | ||
public DateTime BreachDate { get; set; } | ||
|
||
/// <summary> | ||
/// The date and time (precision to the minute) the breach was added to the system in ISO 8601 format. | ||
/// </summary> | ||
public DateTime AddedDate { get; set; } | ||
|
||
/// <summary> | ||
/// The date and time (precision to the minute) the breach was modified in ISO 8601 format. This will only differ from the AddedDate attribute if other attributes represented here are changed or data in the breach itself is changed (i.e. additional data is identified and loaded). It is always either equal to or greater then the AddedDate attribute, never less than. | ||
/// </summary> | ||
public DateTime ModifiedDate { get; set; } | ||
|
||
/// <summary> | ||
/// The total number of accounts loaded into the system. This is usually less than the total number reported by the media due to duplication or other data integrity issues in the source data. | ||
/// </summary> | ||
public int PwnCount { get; set; } | ||
|
||
/// <summary> | ||
/// Contains an overview of the breach represented in HTML markup. The description may include markup such as emphasis and strong tags as well as hyperlinks. | ||
/// </summary> | ||
public string Description { get; set; } = null!; | ||
|
||
/// <summary> | ||
/// This attribute describes the nature of the data compromised in the breach and contains an alphabetically ordered string array of impacted data classes. | ||
/// </summary> | ||
public string[] DataClasses { get; set; } = []; | ||
|
||
/// <summary> | ||
/// Indicates that the breach is considered unverified. An unverified breach may not have been hacked from the indicated website. An unverified breach is still loaded into HIBP when there's sufficient confidence that a significant portion of the data is legitimate. | ||
/// </summary> | ||
public bool IsVerified { get; set; } | ||
|
||
/// <summary> | ||
/// Indicates that the breach is considered fabricated. A fabricated breach is unlikely to have been hacked from the indicated website and usually contains a large amount of manufactured data. However, it still contains legitimate email addresses and asserts that the account owners were compromised in the alleged breach. | ||
/// </summary> | ||
public bool IsFabricated { get; set; } | ||
|
||
/// <summary> | ||
/// Indicates if the breach is considered sensitive. The public API will not return any accounts for a breach flagged as sensitive. | ||
/// </summary> | ||
public bool IsSensitive { get; set; } | ||
|
||
/// <summary> | ||
/// Indicates if the breach has been retired. This data has been permanently removed and will not be returned by the API. | ||
/// </summary> | ||
public bool IsRetired { get; set; } | ||
|
||
/// <summary> | ||
/// Indicates if the breach is considered a spam list. This flag has no impact on any other attributes but it means that the data has not come as a result of a security compromise. | ||
/// </summary> | ||
public bool IsSpamList { get; set; } | ||
|
||
/// <summary> | ||
/// A URI that specifies where a logo for the breached service can be found. Logos are always in PNG format. | ||
/// </summary> | ||
public string LogoPath { get; set; } = null!; | ||
} | ||
// Copyright (c) David Pine. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace HaveIBeenPwned.Client.Abstractions; | ||
|
||
/// <summary> | ||
/// See <a href="https://haveibeenpwned.com/api/v3#BreachModel"></a> | ||
/// </summary> | ||
public sealed class BreachDetails : BreachHeader | ||
{ | ||
/// <summary> | ||
/// A descriptive title for the breach suitable for displaying to end users. It's unique across all breaches but individual values may change in the future (i.e. if another breach occurs against an organisation already in the system). If a stable value is required to reference the breach, refer to the "Name" attribute instead. | ||
/// </summary> | ||
public string Title { get; set; } = null!; | ||
|
||
/// <summary> | ||
/// The domain of the primary website the breach occurred on. This may be used for identifying other assets external systems may have for the site. | ||
/// </summary> | ||
public string Domain { get; set; } = null!; | ||
|
||
/// <summary> | ||
/// The date (with no time) the breach originally occurred on in ISO 8601 format. This is not always accurate — frequently breaches are discovered and reported long after the original incident. Use this attribute as a guide only. | ||
/// </summary> | ||
public DateTime BreachDate { get; set; } | ||
|
||
/// <summary> | ||
/// The date and time (precision to the minute) the breach was added to the system in ISO 8601 format. | ||
/// </summary> | ||
public DateTime AddedDate { get; set; } | ||
|
||
/// <summary> | ||
/// The date and time (precision to the minute) the breach was modified in ISO 8601 format. This will only differ from the AddedDate attribute if other attributes represented here are changed or data in the breach itself is changed (i.e. additional data is identified and loaded). It is always either equal to or greater then the AddedDate attribute, never less than. | ||
/// </summary> | ||
public DateTime ModifiedDate { get; set; } | ||
|
||
/// <summary> | ||
/// The total number of accounts loaded into the system. This is usually less than the total number reported by the media due to duplication or other data integrity issues in the source data. | ||
/// </summary> | ||
public int PwnCount { get; set; } | ||
|
||
/// <summary> | ||
/// Contains an overview of the breach represented in HTML markup. The description may include markup such as emphasis and strong tags as well as hyperlinks. | ||
/// </summary> | ||
public string Description { get; set; } = null!; | ||
|
||
/// <summary> | ||
/// This attribute describes the nature of the data compromised in the breach and contains an alphabetically ordered string array of impacted data classes. | ||
/// </summary> | ||
public string[] DataClasses { get; set; } = []; | ||
|
||
/// <summary> | ||
/// Indicates that the breach is considered unverified. An unverified breach may not have been hacked from the indicated website. An unverified breach is still loaded into HIBP when there's sufficient confidence that a significant portion of the data is legitimate. | ||
/// </summary> | ||
public bool IsVerified { get; set; } | ||
|
||
/// <summary> | ||
/// Indicates that the breach is considered fabricated. A fabricated breach is unlikely to have been hacked from the indicated website and usually contains a large amount of manufactured data. However, it still contains legitimate email addresses and asserts that the account owners were compromised in the alleged breach. | ||
/// </summary> | ||
public bool IsFabricated { get; set; } | ||
|
||
/// <summary> | ||
/// Indicates if the breach is considered sensitive. The public API will not return any accounts for a breach flagged as sensitive. | ||
/// </summary> | ||
public bool IsSensitive { get; set; } | ||
|
||
/// <summary> | ||
/// Indicates if the breach has been retired. This data has been permanently removed and will not be returned by the API. | ||
/// </summary> | ||
public bool IsRetired { get; set; } | ||
|
||
/// <summary> | ||
/// Indicates if the breach is considered a spam list. This flag has no impact on any other attributes but it means that the data has not come as a result of a security compromise. | ||
/// </summary> | ||
public bool IsSpamList { get; set; } | ||
|
||
/// <summary> | ||
/// A URI that specifies where a logo for the breached service can be found. Logos are always in PNG format. | ||
/// </summary> | ||
public string LogoPath { get; set; } = null!; | ||
} |
34 changes: 17 additions & 17 deletions
34
src/HaveIBeenPwned.Client.Abstractions/Models/BreachHeader.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
// Copyright (c) David Pine. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace HaveIBeenPwned.Client.Abstractions; | ||
|
||
/// <summary> | ||
/// See <a href="https://haveibeenpwned.com/api/v3#BreachModel"></a> | ||
/// </summary> | ||
public class BreachHeader | ||
{ | ||
/// <summary> | ||
/// A Pascal-cased name representing the breach which is unique across all other breaches. | ||
/// This value never changes and may be used to name dependent assets (such as images) | ||
/// but should not be shown directly to end users (see the "Title" attribute instead). | ||
/// </summary> | ||
public string Name { get; set; } = null!; | ||
} | ||
// Copyright (c) David Pine. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace HaveIBeenPwned.Client.Abstractions; | ||
|
||
/// <summary> | ||
/// See <a href="https://haveibeenpwned.com/api/v3#BreachModel"></a> | ||
/// </summary> | ||
public class BreachHeader | ||
{ | ||
/// <summary> | ||
/// A Pascal-cased name representing the breach which is unique across all other breaches. | ||
/// This value never changes and may be used to name dependent assets (such as images) | ||
/// but should not be shown directly to end users (see the "Title" attribute instead). | ||
/// </summary> | ||
public string Name { get; set; } = null!; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,41 @@ | ||
// Copyright (c) David Pine. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace HaveIBeenPwned.Client.Abstractions; | ||
|
||
/// <summary> | ||
/// See <a href="https://haveibeenpwned.com/API/v3#PasteModel"></a> | ||
/// </summary> | ||
public sealed class Pastes | ||
{ | ||
/// <summary> | ||
/// The paste service the record was retrieved from. | ||
/// Current values are: | ||
/// Pastebin, Pastie, Slexy, Ghostbin, QuickLeak, JustPaste, AdHocUrl, PermanentOptOut, OptOut. | ||
/// </summary> | ||
public string Source { get; set; } = null!; | ||
|
||
/// <summary> | ||
/// The ID of the paste as it was given at the source service. | ||
/// Combined with the <see cref="Source"/> attribute, this can be used to resolve the URL of the paste. | ||
/// </summary> | ||
public string Id { get; set; } = null!; | ||
|
||
/// <summary> | ||
/// The title of the paste as observed on the source site. | ||
/// This may be <see langword="null" /> and if so will be omitted from the response. | ||
/// </summary> | ||
public string? Title { get; set; } = null!; | ||
|
||
/// <summary> | ||
/// The date and time (precision to the second) that the paste was posted. | ||
/// This is taken directly from the paste site when this information is available but may be null if no date is published. | ||
/// </summary> | ||
public DateTime Date { get; set; } | ||
|
||
/// <summary> | ||
/// The number of emails that were found when processing the paste. | ||
/// Emails are extracted by using the regular expression <c>\b[a-zA-Z0-9\.\-_\+]+@[a-zA-Z0-9\.\-_]+\.[a-zA-Z]+\b</c>. | ||
/// </summary> | ||
public int EmailCount { get; set; } | ||
} | ||
// Copyright (c) David Pine. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace HaveIBeenPwned.Client.Abstractions; | ||
|
||
/// <summary> | ||
/// See <a href="https://haveibeenpwned.com/API/v3#PasteModel"></a> | ||
/// </summary> | ||
public sealed class Pastes | ||
{ | ||
/// <summary> | ||
/// The paste service the record was retrieved from. | ||
/// Current values are: | ||
/// Pastebin, Pastie, Slexy, Ghostbin, QuickLeak, JustPaste, AdHocUrl, PermanentOptOut, OptOut. | ||
/// </summary> | ||
public string Source { get; set; } = null!; | ||
|
||
/// <summary> | ||
/// The ID of the paste as it was given at the source service. | ||
/// Combined with the <see cref="Source"/> attribute, this can be used to resolve the URL of the paste. | ||
/// </summary> | ||
public string Id { get; set; } = null!; | ||
|
||
/// <summary> | ||
/// The title of the paste as observed on the source site. | ||
/// This may be <see langword="null" /> and if so will be omitted from the response. | ||
/// </summary> | ||
public string? Title { get; set; } = null!; | ||
|
||
/// <summary> | ||
/// The date and time (precision to the second) that the paste was posted. | ||
/// This is taken directly from the paste site when this information is available but may be null if no date is published. | ||
/// </summary> | ||
public DateTime Date { get; set; } | ||
|
||
/// <summary> | ||
/// The number of emails that were found when processing the paste. | ||
/// Emails are extracted by using the regular expression <c>\b[a-zA-Z0-9\.\-_\+]+@[a-zA-Z0-9\.\-_]+\.[a-zA-Z]+\b</c>. | ||
/// </summary> | ||
public int EmailCount { get; set; } | ||
} |
Oops, something went wrong.