Change the JWT signing key
What this page covers
Every choice of --Persistence, --Auth, --IncludeTests and --Aspire: a label says which options a part is for. The copy in your app's docs/ folder has only the parts for yours. ApiHost stands for your app's name.
Jwt:SigningKey signs the access tokens. Change it if it may have leaked, or on a schedule.
- Generate a new key:
openssl rand -base64 48. - Set it where the app reads it (
Jwt__SigningKey, orJWT_SIGNING_KEYindeploy/.env), and restart every instance.
Access tokens signed with the old key stop working at once. Refresh tokens don't depend on the key (they're random values, stored hashed), so signed-in users' browsers get a 401, refresh, and carry on without noticing.
If the key leaked
Someone with the key could have made their own access tokens. Changing the key stops those at once. To also sign everyone out, delete the stored refresh tokens:
Marten
DELETE FROM mt_doc_refreshtoken;EF Core
DELETE FROM "RefreshTokens";Everyone then logs in again. Their passwords are unaffected: the key never touches them.