Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/content/docs/graphql/explanation/decisions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ Validation runs once, in one place, before any handler. Handlers only ever see v

Authentication is a choice you make when you create the solution. With `--include-auth`, every query and mutation, `version` included, carries `[Authorize]` and needs a valid JWT bearer token. Without it, there's no authentication code at all, rather than code that sits there switched off. There's nothing to leave half configured, and nothing to read past when you don't need it. See [Secure the API](/graphql/guides/secure-the-api/).

## Open only on purpose

A deployed API without authentication refuses to start unless `Authentication:AllowAnonymous` says open is fine. The template can't tell whether you meant to ship an open API or forgot a setting, so it makes you say so once, in that environment's own settings, where the next person can see it. Your machine is exempt: `Development` and `docker` start open, because that's where you try things. See [Security](/graphql/reference/security/).

## SQLite next to the app

The template needs a database that works in a container and on a laptop without any setup. SQLite does that, with [real caveats](/graphql/guides/database/). It's there to show the shape of Infrastructure, not to be your production database.
Expand Down
2 changes: 1 addition & 1 deletion src/content/docs/graphql/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ You need the [.NET 10 SDK](https://dotnet.microsoft.com/download/dotnet/10.0). [
- Presentation.Tests.Unit/
</FileTree>

4. Run it. The `local` environment seeds sample data and logs to the console, so there's nothing to set up.
4. Run it. The `Development` environment seeds sample data and logs to the console, so there's nothing to set up.

```bash
dotnet run --project ./src/Presentation
Expand Down
4 changes: 2 additions & 2 deletions src/content/docs/graphql/guides/database.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The API keeps its data in a SQLite file called `movie-reviews.db`. With `dotnet

## When the database is created

Every time the API starts, it applies any pending Entity Framework Core migrations. If `Database:SeedSampleData` is `true` and the database is empty, it also seeds the sample movies, authors and reviews. It's on in `appsettings.local.json` and `appsettings.docker.json`, and off everywhere else, so a deployed copy never starts life full of fake reviews.
Every time the API starts, it applies any pending Entity Framework Core migrations. If `Database:SeedSampleData` is `true` and the database is empty, it also seeds the sample movies, authors and reviews. It's on in `appsettings.Development.json` and `appsettings.docker.json`, and off everywhere else, so a deployed copy never starts life full of fake reviews.

The sample data uses a fixed seed, so every machine gets the same 15 authors, the same movies and the same ids. That's why the examples in these docs can name a movie id and expect it to exist on your laptop too.

Expand All @@ -30,7 +30,7 @@ The next start builds a fresh database and seeds it again.
Set `ConnectionStrings__MovieReviews`. To keep everything in memory, which is what the tests do:

```bash
docker run --rm -p 7330:7330 -e DOTNET_ENVIRONMENT=docker \
docker run --rm -p 127.0.0.1:7330:7330 -e DOTNET_ENVIRONMENT=docker \
-e ConnectionStrings__MovieReviews="Data Source=MovieReviews;Mode=Memory;Cache=Shared" \
worksonmymachine-movies:local
```
Expand Down
2 changes: 1 addition & 1 deletion src/content/docs/graphql/guides/make-it-yours.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ The code below assumes you named the solution `WorksOnMyMachine.Movies`. Swap in
x.GetRequiredService<EntityFrameworkMovieReviewsRepository>());
```

- **`Extensions/MovieReviewsDbContextExtensions.cs`** (`sample-data`): give `local` and `docker` some cinemas to look at. Add this to `AddData` before `SaveChanges`:
- **`Extensions/MovieReviewsDbContextExtensions.cs`** (`sample-data`): give `Development` and `docker` some cinemas to look at. Add this to `AddData` before `SaveChanges`:

```csharp
var cinemas = new Faker<Cinema>()
Expand Down
6 changes: 3 additions & 3 deletions src/content/docs/graphql/guides/run-locally.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sidebar:

import { Tabs, TabItem, Aside } from '@astrojs/starlight/components';

There are two ready-made environments. `local` is for `dotnet run`: sample data on, logs to the console. `docker` is for Docker Compose: sample data on, logs, traces and metrics to the Aspire dashboard, database on a volume. Both are for your machine. Neither is for production, which is why neither is the default.
There are two ready-made environments. `Development` is for `dotnet run`: sample data on, logs to the console. `docker` is for Docker Compose: sample data on, logs, traces and metrics to the Aspire dashboard, database on a volume. Both are for your machine. Neither is for production, which is why neither is the default.

## Run it

Expand All @@ -17,7 +17,7 @@ There are two ready-made environments. `local` is for `dotnet run`: sample data
dotnet run --project ./src/Presentation
```

`launchSettings.json` sets the environment to `local` and listens on [https://localhost:7331](https://localhost:7331), and on `http://localhost:7330`, which redirects to it. If your browser or `curl` doesn't trust the .NET development certificate yet, run `dotnet dev-certs https --trust` once.
`launchSettings.json` sets the environment to `Development` and listens on [https://localhost:7331](https://localhost:7331), and on `http://localhost:7330`, which redirects to it. If your browser or `curl` doesn't trust the .NET development certificate yet, run `dotnet dev-certs https --trust` once.
</TabItem>
<TabItem label="Docker Compose">
```bash
Expand All @@ -29,7 +29,7 @@ There are two ready-made environments. `local` is for `dotnet run`: sample data
<TabItem label="Docker">
```bash
docker build . --target run --tag worksonmymachine-movies:local
docker run --rm -p 7330:7330 -e DOTNET_ENVIRONMENT=docker worksonmymachine-movies:local
docker run --rm -p 127.0.0.1:7330:7330 -e DOTNET_ENVIRONMENT=docker worksonmymachine-movies:local
```

Without Compose there's no collector, so the logs stay on the console and nothing else is exported. Set `OTEL_EXPORTER_OTLP_ENDPOINT` to send them to a collector of your own.
Expand Down
18 changes: 15 additions & 3 deletions src/content/docs/graphql/guides/secure-the-api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sidebar:

import { Steps, Aside } from '@astrojs/starlight/components';

Out of the box the API runs wide open, and there's no authentication code in it at all. That's lovely on a laptop and less lovely in production, so here's how to close the door.
Out of the box there's no authentication code in the API at all. On your machine it runs wide open, which is lovely. Deployed anywhere else it refuses to start until you either turn authentication on or tell it open is fine, which is less lovely but much safer. Here's how to close the door properly.

## Turn it on

Expand Down Expand Up @@ -38,6 +38,18 @@ Out of the box the API runs wide open, and there's no authentication code in it

</Steps>

## Try it on your machine

You don't need your real authority to try the API. Let .NET make you a development token:

```bash
dotnet user-jwts create --project src/Presentation
```

It prints a token, keeps the signing key in your user secrets and writes the issuer and audiences into `appsettings.Development.json`. From then on `dotnet run` accepts its tokens instead of your authority's. Nothing changes anywhere else: user secrets and that file only load in `Development`, and the API refuses to start with development tokens set up in any other environment. If you commit the file, everyone's `dotnet run` switches to development tokens, and each person makes their own with the same command.

In Nitro at [https://localhost:7331/graphql](https://localhost:7331/graphql), open the connection settings and add a header: `Authorization` with `Bearer <token>`. The schema loads once the header is there. Run `dotnet user-jwts create` again for a fresh token. To go back to your authority, run `dotnet user-jwts clear --project src/Presentation` and delete the `Authentication` block from `appsettings.Development.json`.

## Add it to a solution you already have

Created the solution without `--include-auth`? The code isn't hiding behind a setting, it isn't there at all, so it goes in by hand. The quickest way to see every line is to let the template show you. Create a second solution with the same name and `--include-auth` next to yours, then compare the two:
Expand All @@ -59,12 +71,12 @@ Copy across what's new: the `Microsoft.AspNetCore.Authentication.JwtBearer` pack
{ "errors": [ { "message": "The current user is not authorized to access this resource.", "extensions": { "code": "AUTH_NOT_AUTHENTICATED" } } ] }
```

- The `version` query needs one too. The schema, Nitro, `/health/live` and `/health/ready` stay open, so load balancers and curious humans can still check the lights are on.
- The `version` query needs one too. So does the schema: introspection answers only with a token and the `?sdl` download is switched off, so nobody can map the API without signing in, and Nitro shows an empty schema until you add one. Nitro itself, `/health/live` and `/health/ready` stay open, so load balancers and curious humans can still check the lights are on.
- Tokens are validated against the authority's published keys, so there's no secret to store and nothing to rotate on your side.

## How it works

`AuthenticationSettings` reads the `Authentication` section, and the API registers the JWT bearer handler, the normal authorization services and Hot Chocolate's authorization. Every movie, author and review query, every mutation and the `version` query carry `[Authorize]`. An empty authority still lets every request through, which is how the tests run, so make sure every environment you deploy to sets one.
`AuthenticationSettings` reads the `Authentication` section, and the API registers the JWT bearer handler, the normal authorization services and Hot Chocolate's authorization. Every movie, author and review query, every mutation and the `version` query carry `[Authorize]`. An empty authority turns authentication off. `Development` and `docker` allow that, which is how the tests run; anywhere else the API refuses to start rather than run open. A set authority has to be an `https` URL.

<Aside type="note" title="All or nothing">
With `--include-auth`, every protected field declares it, so there's never a moment where a field was forgotten. Without it, there's no half-built gate left open by mistake. There's just no gate.
Expand Down
12 changes: 8 additions & 4 deletions src/content/docs/graphql/guides/ship-the-container.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,19 @@ The version is stamped into the assemblies, so the `version` query tells you exa

| Environment | Logs | Sample data | Meant for |
| --- | --- | --- | --- |
| `local` | Console | On | `dotnet run` on your machine |
| `Development` | Console | On | `dotnet run` on your machine |
| `docker` | Console, and OTLP through the collector | On | `docker compose up` on your machine |
| Anything else | Whatever you configure | Off | Production, staging, and anywhere data matters |

For production, pick a name like `production`, add an `appsettings.production.json` with a Serilog sink you can read, and leave `Database:SeedSampleData` alone. The default is off, so a fresh database stays empty until something real writes to it.
The image sets no environment of its own, so it runs as `Production` until you pass `DOTNET_ENVIRONMENT`. Add an `appsettings.Production.json` with a Serilog sink you can read, and leave `Database:SeedSampleData` alone. The default is off, so a fresh database stays empty until something real writes to it.

<Aside type="caution" title="It won't start open">
Every environment except `Development` and `docker` counts as deployed. With authentication off, the API refuses to start there and says why, so nobody ships an open API by accident. If open is what you want, say so with `Authentication__AllowAnonymous=true`. The [security reference](/graphql/reference/security/) has the full list of what's on by default.
</Aside>

## Put it behind HTTPS

The container only listens on HTTP, and it expects something in front of it to end TLS: a load balancer, a reverse proxy or your platform's ingress. Outside the `local` and `Development` environments it sends an HSTS header, and it redirects HTTP to HTTPS once it knows an HTTPS port to send people to, such as `ASPNETCORE_HTTPS_PORT=443`. Tell it about the proxy too:
The container only listens on HTTP, and it expects something in front of it to end TLS: a load balancer, a reverse proxy or your platform's ingress. Outside the `Development` environment it sends an HSTS header, and it redirects HTTP to HTTPS once it knows an HTTPS port to send people to, such as `ASPNETCORE_HTTPS_PORT=443`. Tell it about the proxy too:

```bash
ASPNETCORE_FORWARDEDHEADERS_ENABLED=true
Expand All @@ -57,7 +61,7 @@ The SQLite file lives in `/app/data`. Mount a volume there or, better, [point In

## Turn authentication on

In a solution created with `--include-auth`, set `Authentication__Authority` and `Authentication__Audience` as environment variables to point each environment at its own authorization server. Without `--include-auth` there's nothing to turn on yet. The [security guide](/graphql/guides/secure-the-api/) has the details.
In a solution created with `--include-auth`, set `Authentication__Authority` and `Authentication__Audience` as environment variables to point each environment at its own authorization server. The authority has to be an `https` URL and come with an audience, or the API won't start. Without `--include-auth` there's nothing to turn on yet, so set `Authentication__AllowAnonymous=true` instead if the API really is meant for everyone. The [security guide](/graphql/guides/secure-the-api/) has the details.

<Aside type="tip" title="Where to run it">
Azure Container Apps, AWS App Runner and ECS, Google Cloud Run, Fly.io, Kubernetes, or a Raspberry Pi under the desk. The image doesn't care. It only wants port 7330 (point the platform's target port at it), a `DOTNET_ENVIRONMENT`, and to be left alone.
Expand Down
13 changes: 13 additions & 0 deletions src/content/docs/graphql/guides/upgrade.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Every solution made since the January 2027 release has a `.lmca.json` at the roo
"options": {
"name": "WorksOnMyMachine.Movies",
"authorName": "Jane Citizen",
"rateLimiting": false,
"authentication": {
"Authority": "https://login.example.com",
"Audience": ""
Expand All @@ -40,6 +41,7 @@ Each option is a `dotnet new` option:
| --- | --- |
| `name` | `--name` |
| `authorName` | `--authorName` |
| `rateLimiting` | `--include-rate-limiting` when it's `true` |
| `authentication` | `--include-auth`, with `--authority` and `--audience` from inside it. Leave all three off when it's `null` |

<Aside type="note" title="No .lmca.json?">
Expand Down Expand Up @@ -132,6 +134,17 @@ Coding agents are good at this. Ask yours to apply the patch, resolve the confli

Each release's notes on GitHub link here. Each release gets a few lines below on what's worth bringing in and anything that needs care, newest first.

### 2027.01.01

The safe by default release. It brings security headers on every response, Compose ports that only listen on your machine, development tokens for solutions with authentication, and a new `--include-rate-limiting` option. The [security reference](/graphql/reference/security/) has the full list. Four changes need care:

- **`local` is now `Development`.** The patch renames `appsettings.local.json` to `appsettings.Development.json` and updates `launchSettings.json`. If you added settings of your own to `appsettings.local.json`, check they came across, and change `DOTNET_ENVIRONMENT=local` anywhere you set it yourself, such as a script or an IDE profile.
- **A deployed API with authentication off no longer starts.** Every environment except `Development` and `docker` now counts as deployed. Before you roll this out, either [turn authentication on](/graphql/guides/secure-the-api/) or set `Authentication__AllowAnonymous=true` in each environment that's open on purpose.
- **The image builds as `Production`.** If a pipeline runs the image on its own to smoke test it, pass `-e DOTNET_ENVIRONMENT=docker`, as `docker compose` does.
- **An authority needs an audience.** In a solution with authentication, an empty `Authentication:Audience` used to turn every token away without saying why. Now the API says so at startup, so set the audience your tokens are issued for, and `--audience` is required with `--include-auth` when you generate the new copy.

To add rate limiting to a solution made without it, generate the new copy with `--include-rate-limiting` and the old one without, and the patch carries the limiter in.

### 2026.12.02.245

The release we launched with. Solutions made from it don't have a `.lmca.json`; see [Find your release and options](#find-your-release-and-options).
Loading