Documentation

Getting Started

← All docs

Getting Started

Install SqlOS and run the example stack in five minutes.

Install

dotnet add package SqlOS

Configure services

Register SqlOS with your EF Core DbContext. Enable one or both modules:

builder.AddSqlOS<AppDbContext>(options =>
{
    options.UseAuthServer();
    options.UseFGA();
});

Set up your DbContext

Your context implements both module interfaces and registers their models:

public sealed class AppDbContext : DbContext,
    ISqlOSAuthServerDbContext,
    ISqlOSFgaDbContext
{
    public DbSet<Project> Projects => Set<Project>();

    public IQueryable<SqlOSFgaAccessibleResource> IsResourceAccessible(
        string subjectId,
        string permissionKey)
        => FromExpression(() =>
            IsResourceAccessible(subjectId, permissionKey));

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        modelBuilder.UseSqlOS(GetType());
    }
}

Map routes

var app = builder.Build();
app.MapSqlOS();

This gives you:

PathWhat it does
/sqlosAdmin dashboard
/sqlos/auth/*OAuth 2.0 endpoints (authorize, token, JWKS)
/sqlos/admin/authAuth management UI
/sqlos/admin/fgaFGA management UI

Seed a client

Register your frontend as an OAuth client so users can sign in immediately:

options.UseAuthServer(auth =>
{
    auth.SeedBrowserClient(
        "my-app",
        "My Application",
        "http://localhost:3000/auth/callback");
});

Protect the dashboard

Set a dashboard password in appsettings.json:

{
  "SqlOS": {
    "Dashboard": {
      "AuthMode": "Password",
      "Password": "your-strong-password"
    }
  }
}

Run the example stack

The repo includes a complete example with API, Next.js frontend, Angular frontend, and Expo mobile app:

cd examples/SqlOS.Example.Web && npm install
cd /path/to/SqlOS
dotnet run --project examples/SqlOS.Example.AppHost/SqlOS.Example.AppHost.csproj
URLApp
http://localhost:5062/sqlos/Dashboard
http://localhost:5062/swaggerSwagger UI
http://localhost:3010/Next.js app
http://localhost:4200/Angular app

Schema management

SqlOS owns its own database schema. On host startup, SqlOS runs embedded SQL scripts to create or update tables. Your app's EF Core migrations do not manage SqlOS tables. If you apply EF migrations before the host runs, call SqlOSBootstrapper.InitializeAsync() once beforehand (see the example API for a pattern when consumer tables reference SqlOS).

Next steps