A simple jwt authentication library for ASP.Net 6. AuthEndpoints library provides a set of Web API controllers and minimal api endpoints to handle basic web & JWT authentication actions such as registration, email verification, reset password, create jwt, etc. It works with custom identity user model. AuthEndpoints is built with the aim of increasing developer productivity.
- Supported endpoints:
- sign-up
- sign-in (create jwt)
- email verification
- refresh jwt
- verify jwt
- user profile (retrieving)
- reset password
- change password
- enable 2fa & login 2fa (via email)
- JWT support
- Works with a symmetric key (shared secret) or asymmetric keys (the private key of a private–public pair).
- Works with custom identity user
- Only works with IdentityUser or custom identity user
- No session based auth support
- 2fa via email
The easiest way to install AuthEndpoints is via NuGet
Install the library using the following .net cli command:
dotnet add package AuthEndpoints
or in Visual Studio's Package Manager Console, enter the following command:
Install-Package AuthEndpoints
Edit Program.cs, then add the required services:
builder.Services.AddAuthorization();
builder.Services.AddDbContext<MyDbContext>(options => { });
builder.Services.AddIdentityCore<MyCustomIdentityUser>()
.AddEntityFrameworkStores<MyDbContext>()
.AddDefaultTokenProviders();
then add auth endpoints services and enable jwt bearer authentication
builder.Services
.AddAuthEndpoints<string, MyCustomIdentityUser>() // Use the default and minimum config
.AddJwtBearerAuthScheme();
public class MyBaseAuthController : BasicAuthenticationController<string, MyCustomIdentityUser>
{}
public class MyJwtController : JwtController<string, MyCustomIdentityUser>
{}
public class MyTwoFactorController : TwoStepVerificationController<string, MyCustomIdentityUser>
{}
or
Install AuthEndpoints.MinimalApi
package, then edit Program.cs:
builder.Services
.AddAuthEndpoints<string, MyCustomIdentityUser>()
.AddAllEndpointDefinitions() // add basic auth, jwt, 2fa endpoints
.AddJwtBearerAuthScheme();
var app = builder.Build();
...
app.UseAuthentication();
app.UseAuthorization();
...
app.MapAuthEndpoints(); // Map minimal api endpoints
app.Run();
Checkout docs for more info.
Documentation is available at https://madeyoga.github.io/AuthEndpoints/ and in docs directory.
Your contributions are always welcome! simply send a pull request! The up-for-grabs label is a great place to start. If you find a flaw, please open an issue or a PR and let's sort things out.
The documentation is far from perfect so every bit of help is more than welcome.