AuthScape

Docs

User Secrets

Securely store development secrets outside of your codebase.

User Secrets keep sensitive development configuration out of source control.

Initialize User Secrets

bash
cd AuthScape.API
dotnet user-secrets init

This adds a UserSecretsId to your .csproj:

xml
<PropertyGroup>
<UserSecretsId>your-guid-here</UserSecretsId>
</PropertyGroup>

Setting Secrets

bash
# Set individual secrets
dotnet user-secrets set "ConnectionStrings:DefaultConnection" "Server=localhost;..."
dotnet user-secrets set "AppSettings:Stripe:SecretKey" "sk_test_xxx"
dotnet user-secrets set "AppSettings:SendGrid:ApiKey" "SG.xxx"

Listing Secrets

bash
dotnet user-secrets list

Removing Secrets

bash
# Remove single secret
dotnet user-secrets remove "AppSettings:Stripe:SecretKey"
# Clear all secrets
dotnet user-secrets clear

Secrets Location

Secrets are stored outside the project:

  • Windows: %APPDATA%\Microsoft\UserSecrets\<user_secrets_id>\secrets.json
  • Linux/Mac: ~/.microsoft/usersecrets/<user_secrets_id>/secrets.json

secrets.json Format

json
{
"ConnectionStrings:DefaultConnection": "Server=localhost;Database=AuthScape;...",
"AppSettings:Stripe:SecretKey": "sk_test_xxx",
"AppSettings:SendGrid:ApiKey": "SG.xxx"
}

Loading in Program.cs

User secrets are loaded automatically in Development:

csharp
var builder = WebApplication.CreateBuilder(args);
// User secrets loaded automatically when:
// - Environment is Development
// - UserSecretsId is set in .csproj

Best Practices

  1. Never commit secrets - Add secrets.json to .gitignore
  2. Use for development only - Use Azure Key Vault or AWS Secrets Manager in production
  3. Document required secrets - Maintain a template of required keys

Next Steps

  • Environment Variables
  • Azure Key Vault