Buzzytom.Extensions.Authentication.Api
1.0.0
dotnet add package Buzzytom.Extensions.Authentication.Api --version 1.0.0
NuGet\Install-Package Buzzytom.Extensions.Authentication.Api -Version 1.0.0
<PackageReference Include="Buzzytom.Extensions.Authentication.Api" Version="1.0.0" />
paket add Buzzytom.Extensions.Authentication.Api --version 1.0.0
#r "nuget: Buzzytom.Extensions.Authentication.Api, 1.0.0"
// Install Buzzytom.Extensions.Authentication.Api as a Cake Addin
#addin nuget:?package=Buzzytom.Extensions.Authentication.Api&version=1.0.0
// Install Buzzytom.Extensions.Authentication.Api as a Cake Tool
#tool nuget:?package=Buzzytom.Extensions.Authentication.Api&version=1.0.0
Extensions.Authentication
Lean token extensions for issuing/validating tokens, automatically creating a private key and creating password salts. Compatible with Asp.Net Core 2.1.
Usage Guide
Install the NuGet package
Buzzytom.Extensions.Authentication
Add using statements to get the extensions.
using Extensions.Authentication;
using Extensions.Authentication.JwtBearer;
In the ConfigureServices of your application (or equivalent) add the following calls to register the required services and middleware.
public void ConfigureServices(IServiceCollection services)
{
// Register other services here, like entity framework
// Adds a ITokenService to the dependency services
services.AddTokenService();
// Adds a IValidatorService to the dependency services
services.AddValidationService();
// Adds:
// - JWT middleware services supporting the Authorize attribute
// - Adds a ISymmetricKeyProvider to the dependency services
services.AddJwt();
}
Make sure your application is configured to use authentication.
public void Configure(IApplicationBuilder application)
{
// Configure other services here
// Enable authentication, JWT middleware does not work without this
application.UseAuthentication();
// Configure other services here. E.g. services.UseMvc();
}
Example controller to issue authentication tokens.
[Route("/api/account")]
public class AuthenticationController : ControllerBase
{
private readonly ITokenService tokenService;
private readonly IBearerTokenService bearerTokenService;
public AuthenticationController(ITokenService tokenService,
IBearerTokenService, bearerTokenService)
{
this.tokenService = tokenService;
this.bearerTokenService = bearerTokenService;
}
[HttpPost]
[Route("authenticate")]
public string Authenticate([FromBody] AuthenticateRequest request)
{
// DON'T ACTUALLY DO IT LIKE THIS
// THIS IS ONLY AN EXAMPLE
YourUserType user = GetUserFromYourPersistentStore(request.Email);
string requestHash = tokenService.Hash(request.Password, user.Salt);
if (requestHash == user.PasswordHash)
return bearerTokenService.CreateAuthenticationToken(new Claim(ClaimTypes.Email, request.Email.ToLower()));
else
return null;
}
}
Example registration controller
[Route("/api/account")]
public class RegisterController : ControllerBase
{
private readonly ITokenService service;
public AuthenticationController(ITokenService service)
{
this.service = service;
}
[HttpPost]
[Route("register")]
public void Register([FromBody] RegisterRequest request)
{
// DON'T ACTUALLY DO IT LIKE THIS
// THIS IS ONLY AN EXAMPLE
// Perform request validation checks
bool exists = CheckUserDoesNotExistInYourPersistentStore(request.Email);
if (exists)
return false;
// Create the password
string salt = service.GenerateSalt();
string hash = service.Hash(request.Password, salt);
// Create the new user
CreateNewUserInYourPersistentStore(new YourUser
{
Email = request.Email,
Salt = salt,
PasswordHash = hash
// Other properties
});
}
}
Improvements
Raise them as an issue
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Buzzytom.Extensions.Authentication.Api:
Package | Downloads |
---|---|
Buzzytom.Extensions.Authentication
Lean token extensions for issuing/validating tokens, automatically creating a private key and creating password salts. This is the API project, for concrete implementations see other projects that share this projects name |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 879 | 10/14/2018 |
Initial release.