Skip to content
Configuration schema

Configuration schema

The section passed to AddHmac or AddHmacManager binds to an array of policies.

[
  {
    "Name": "Some_Policy",
    "Keys": {
      "PublicKey": "37e3e675-370a-4ba9-af74-68f99b539f03",
      "PrivateKey": "zvg29s2cQ4idOqbUJWETOw=="
    },
    "Algorithms": {
      "ContentHashAlgorithm": "SHA256",
      "SigningHashAlgorithm": "HMACSHA256"
    },
    "Nonce": {
      "CacheType": "Memory",
      "MaxAgeInSeconds": 100
    },
    "Schemes": [
      {
        "Name": "Some_Scheme",
        "Headers": [
          {
            "Name": "Some_Header_1",
            "ClaimType": "Header_1_ClaimType"
          }
        ]
      }
    ]
  }
]
PropertyValues
NamePolicy name, matched against the Hmac-Policy header
Keys.PublicKeyA GUID string
Keys.PrivateKeyA base64-encoded string
Algorithms.ContentHashAlgorithmSHA1, SHA256, SHA512
Algorithms.SigningHashAlgorithmHMACSHA1, HMACSHA256, HMACSHA512
Nonce.CacheTypeMemory, Distributed
Nonce.MaxAgeInSecondsReplay window, in seconds
Schemes[].NameScheme name, matched against the Hmac-Scheme header
Schemes[].Headers[].NameHeader name
Schemes[].Headers[].ClaimTypeClaim the header maps to; defaults to the header name

Values are validated when the policy is built, so an invalid key or algorithm fails at startup rather than on the first request.

Distributed requires an IDistributedCache to be registered. If none is, that is reported at Warning as event 1201 rather than failing quietly — see nonce and replay.

PrivateKey is a shared secret and appsettings.json is committed. Supply it from user secrets, an environment variable or a secret store and let configuration composition merge it in.

See configuration binding for how to wire it up, including reload behaviour.