Skip to content

Installation

Aufy is built on top of ASP.NET Core Identity framework, which is database agnostic. Currently only Entity Framework Core implementation is available, but you can use any other database provider.

Install nuget package

Terminal window
dotnet add package Aufy.EntityFrameworkCore

Create DbContext

Add a new DbContext class that inherits from AufyDbContext.

MyAuthDbContext.cs
public class MyAuthDbContext : AufyDbContext<AufyUser>
{
public MyAuthDbContext(DbContextOptions<MyAuthDbContext> options) : base(options)
{
}
}

Register your DbContext in DI container

Sample registration with SQLite database:

appsettings.json
{
"ConnectionStrings": {
"DefaultConnection": "Data Source=auth.db"
}
}
Program.cs
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection")
builder.Services.AddDbContext<MyAuthDbContext>(options => options.UseSqlite(connectionString));

Register Aufy services in DI container

Program.cs
builder.Services
.AddAufy<AufyUser>(builder.Configuration, opts => { /* configure options here */ })
.AddEntityFrameworkStore<MyAuthDbContext, AufyUser>()

Add JWT Bearer configuration

appsettings.json
{
"Aufy": {
"JwtBearer": {
"SigningKey": "super secret key",
"Issuer": "MY_ISSUER",
"Audience": "MY_AUDIENCE"
}
}
}

Add authentication and authorization middleware and Aufy endpoints

Program.cs
app.UseAuthentication();
app.UseAuthorization();
app.MapAufyEndpoints();

Add migrations and update database

Terminal window
dotnet ef migrations add MIGRATION_NAME
dotnet ef database update

Congratulations! You have successfully installed Aufy!