Oc6.Library 2.1.55

Oc6.Library

Things I use a lot.

Table of content

AspNetCore

Time


AspNetCore

Auth

ApiKey

Provides ApiKey authentication for ASP.NET Core applications.

Expects an ApiKey added to the HTTP header X-Api-Key with the secret key.

Dependency injection
//adds IOption<ApiKeyConfig> and set up authentication.
services.AddApiKeyAuthentication(configuration)

...

//Use the authentication middleware
application.UseApiKeyAuthentication();
Usage

Just use regular [Authorize] attribute on your controllers or actions.

Generation
//Generate a new ApiKey
ApiKeyGenerator.GenerateApiKey();
//uses System.Security.Cryptography.RandomNumberGenerator to generate a secure random key

//Generate a new ApiKey with specific length
int length = ...
ApiKeyGenerator.GenerateApiKey(length);

Time

Provides [ITimeProvider] as a scoped service.

Used to ensures that all requests within the same scope (e.g. HTTP request) get the same time.

Dependency injection

...
//Get scoped
services.AddScopedTimeProvider();

//Get fixed
DateTimeOffset someFixedTime = ...
services.AddFixedTimeProvider(someFixedTime);
...

Usage

...
class SomeClass(ITimeProvider timeProvider)
{
	void SomeMethod()
	{
		...
		var currentTime = timeProvider.UtcNow;
		...
	}
}
...

No packages depend on Oc6.Library.

Version Downloads Last updated
3.0.63 6 12/02/2025
3.0.62 3 11/24/2025
2.1.61 11 10/31/2025
2.1.60 29 10/20/2025
2.1.59 2 10/20/2025
2.1.58 2 10/20/2025
2.1.57 2 10/20/2025
2.1.56 2 10/20/2025
2.1.55 2 10/20/2025
2.1.54 2 10/20/2025
2.1.53 2 10/20/2025
2.1.52 1 10/20/2025
2.1.51 2 10/20/2025
2.1.50 2 10/17/2025
2.1.49 2 10/17/2025
2.1.48 2 10/16/2025
2.1.47 2 10/16/2025
2.0.46 2 10/15/2025
2.0.45 2 10/15/2025
2.0.44 7 10/07/2025
2.0.43 3 10/07/2025
2.0.42 3 10/07/2025
2.0.41 3 10/01/2025
2.0.40 3 10/01/2025
2.0.39 3 10/01/2025
2.0.38 3 09/30/2025
2.0.37 3 09/30/2025
2.0.36 4 09/26/2025