Authorization Server Project Template¶
You can find the official source for the template here:
GitHub – AuthorizationServer Template
Overview¶
The Authorization Server template implements:
- Authentication using JWT Bearer tokens.
- Authorization using claims-based policies.
- API Versioning and CORS configuration.
- Password Policies, Password Expiration, Login Attempt Policies.
- Provider abstraction for storing accounts, refresh tokens, user groups, etc.
- PostgreSQL provider (recommended for production)
- JSON file-based provider (for development/testing, stored in
App_Datafolder)
- Swagger/OpenAPI documentation support.
- HSTS and response compression.
- Serilog logging.
It is ready to run out-of-the-box with either PostgreSQL or file-based JSON repositories, depending on configuration.
For more details on the security-related API endpoints, see:
Web API Security
Switching Providers¶
This template supports two repository provider types:
| Provider Type | Setting | Usage |
|---|---|---|
| PostgreSQL | "Repository:UsePostgreSQL": true |
Stores all authentication data in a PostgreSQL database. Requires a valid connection string in appsettings.json. |
| JSON Files | "Repository:UsePostgreSQL": false |
Stores all authentication data as .json files inside App_Data folder. |
Repository types are switched in appsettings.json or via environment variables.
Example PostgreSQL settings in appsettings.json:
"Repository": {
"UsePostgreSQL": true,
"PostgreSQL": {
"ConnectionString": "Server=localhost;Port=5432;Username=postgres;Password=Solutions!;Database=AccountTest;",
"LogConnectionString": "Server=localhost;Port=5432;Username=postgres;Password=Solutions!;Database=AccountTest;Table=public.logging;"
}
}
Example JSON-based settings in appsettings.json:
"Repository": {
"UsePostgreSQL": false
}
Configuration¶
The main configuration file is appsettings.json.
Key sections include:
AppConfiguration– General server settings.Registration– URIs for account activation, password reset, SMTP server info.Tokens– JWT Issuer, Audience, RSA keys, expiration settings.Repository– Repository provider type and connection strings.Swagger– API documentation title, description, and OpenAPI specification name.PermittedOrigins– Allowed CORS origins.
See the provided appsettings.json for full example values.
First Run: Bootstrap Admin Account¶
On the very first launch—when the repository has no authentication tables yet—the Authorization Server will automatically create the database schema and seed a temporary administrator account so you can sign in and set up real users:
- Username:
demo_admin_to_be_deleted - Password:
webapi
Use this account to log in via the Swagger UI and create the users/admins you need.
Security reminder: Immediately after provisioning your own admin account(s), delete the bootstrap account (or at least change its password) and proceed with your normal hardening steps (e.g., rotate keys, review password/lockout policies).
This bootstrap step runs only when the auth tables are missing. Once the schema exists, the server won’t recreate or reset the account. It works with both the PostgreSQL and JSON providers.
Quick start flow¶
- Start the server (Docker or local).
- Open Swagger at the server URL.
- Sign in with
demo_admin_to_be_deleted/webapi. - Create your permanent admin/user accounts.
- Delete (recommended) or disable the bootstrap account.
Running the Authorization Server¶
1. Using Docker Compose (recommended for quick start)¶
The repository includes a docker-compose.yml file that sets up:
- PostgreSQL database (v11)
- Authorization Server container
- Test Runner container for running automated tests
Run:
docker-compose up --build
This will:
- Create a PostgreSQL container named
authserver_postgres - Build and run the
authservercontainer on port 8080 - Automatically apply configuration from
docker-compose.yml
Swagger UI will be available at:
http://localhost:8080/swagger
2. Running Locally Without Docker¶
If you prefer to run without Docker:
- Make sure the .NET SDK is installed (see the template on GitHub for the current target framework).
- Install and start a PostgreSQL instance.
- Create the database configured in
appsettings.json:(or whatever name of your database, depending on your settings)CREATE DATABASE AccountTest; - Update the
ConnectionStringandLogConnectionStringinappsettings.jsonif needed. - Run the project
- Access Swagger at:
http://localhost:5000/swagger
Related Documentation¶
- Web API Security – Details on
DHI.Services.Security.WebApiusage - Domain Services Overview
- How to Leverage Domain Services
Notes¶
- In production, PostgreSQL is strongly recommended over JSON-based repositories.
- RSA keys in
appsettings.jsonshould be replaced with secure production keys. - Swagger descriptions are loaded from
[AppData]SwaggerInfo.md, which should be customized for your API.