Subscription Key Authentication¶
Configure APIM subscription key authentication for Experience APIs that serve legacy server-to-server clients.
| Property | Value |
|---|---|
| Goal | Allow legacy applications to call your API using an APIM subscription key |
| Prerequisites | Experience API deployed (is_experience_api: true), variable group with keys |
| Time Estimate | 15 minutes |
| Difficulty | Beginner |
Overview¶
Some legacy applications cannot obtain OAuth tokens and need a simpler authentication mechanism. The subscription_key policy type configures your Experience API to accept APIM subscription keys instead of JWT tokens.
The pipeline handles the full lifecycle:
- Terraform creates the APIM subscription using your keys from the variable group
- Crypto registration (opt-in) stores the keys in the Crypto API and records cipher IDs in the Environment Service so legacy .NET apps can retrieve them via
_environmentClient.GetSecureSetting()
When to Use¶
| Scenario | Recommended Policy Type |
|---|---|
| Standard user-delegated or service-to-service | standard |
| Filevine webhook integration | filevine |
| Legacy app that cannot use OAuth | subscription_key |
Use Only When Necessary
Subscription key auth provides weaker security guarantees than OAuth. It does not carry user identity or granular scopes. Only use this when the calling application cannot support OAuth flows.
How It Works¶
sequenceDiagram
participant Legacy App
participant Front Door
participant APIM
participant Backend API
Legacy App->>Front Door: GET /api/exp/your-app/<br/>Ocp-Apim-Subscription-Key: {key}
Front Door->>APIM: Forward request + X-Azure-FDID header
APIM->>APIM: Validate subscription key
APIM->>APIM: Validate Front Door ID
APIM->>APIM: Set x-forward-tenant-origin: corp
APIM->>Backend API: Forward with managed identity token
Backend API-->>APIM: Response
APIM-->>Front Door: Response
Front Door-->>Legacy App: Response
Key differences from standard policy:
- No JWT validation — APIM validates the subscription key natively
- No scopes or roles — all requests are treated as corporate internal
- Managed identity — APIM still authenticates to the backend using managed identity
Step 1: Configure vars.yml¶
In your Experience API's vars.yml, set api_policy_type to subscription_key:
# infra/api/vars.yml
application_name: your-app-name
application_type: Api
api_type: Experience
owner: YourTeam
project_id: your-project-id
api_policy_type: subscription_key
Experience APIs Only
The subscription_key policy type requires api_type: Experience (which sets is_experience_api: true). Terraform validation will fail if you use it with other API types.
Step 2: Add Subscription Keys to Variable Group¶
Store your subscription keys in an Azure DevOps variable group so the pipeline can pass them to Terraform and (optionally) register them in the Crypto API.
Generate Keys¶
Use a password generator (e.g., Keeper) to create a unique key for each environment. Requirements:
- Letters, numbers, hyphens (
-), and underscores (_) only — avoid all other symbols (the pipeline is sensitive to special characters) - Minimum 32 characters, maximum 256
- Different key per environment — do not reuse the same key across TEST, QA, UAT, and PROD
Add Keys to Variable Group¶
- Navigate to Azure DevOps → Pipelines → Library
- Open your application's variable group (the name must match
secretsVariableGroupNamein your pipeline — typically your project ID, e.g.,it-api-exp-yourapp) - Add environment-prefixed entries and mark each as Secret:
| Variable Name | Type | Description |
|---|---|---|
[TEST]primary_key |
Secret | Primary key for TEST |
[QA]primary_key |
Secret | Primary key for QA |
[UAT]primary_key |
Secret | Primary key for UAT |
[PROD]primary_key |
Secret | Primary key for PROD |
Optionally add secondary_key entries for key rotation support:
| Variable Name | Type | Description |
|---|---|---|
[TEST]secondary_key |
Secret | Secondary key for TEST |
[PROD]secondary_key |
Secret | Secondary key for PROD |
Critical
If you rename or use a different variable group, its name must match the secretsVariableGroupName value in your pipeline YAML file.
Treat Subscription Keys as Secrets
Subscription keys grant full access to your API. Mark them as Secret in the variable group and never commit them to source control.
Step 3: Configure Pipeline¶
Add secretsVariableGroupName to both your main pipeline and PR pipeline:
extends:
template: api-service.yml@templates
parameters:
applicationName: ${{ variables.ApplicationName }}
projectId: ${{ variables.ProjectId }}
dotNetVersion: '10.x'
secretsVariableGroupName: 'your-project-id' # Variable group from Step 2
Enable Crypto Registration¶
If legacy .NET callers need to retrieve the subscription key at runtime via _environmentClient.GetSecureSetting(), also add the cryptoRegistration parameter. This stores the keys in the Crypto API and records the cipher IDs in the Environment Service after each deployment.
extends:
template: api-service.yml@templates
parameters:
applicationName: ${{ variables.ApplicationName }}
projectId: ${{ variables.ProjectId }}
dotNetVersion: '10.x'
secretsVariableGroupName: 'your-project-id'
cryptoRegistration:
enabled: true
systemName: 'your-project-id' # Name of the Crypto system
systemType: 'webapp' # console, windowsservice, webapp, guidewire, desktopapp, script, other
allowedSystems: # Optional: other callers allowed to decrypt the keys
- name: 'CCClaimDataApi'
type: 'webapp'
| Parameter | Required | Default | Description |
|---|---|---|---|
enabled |
Yes | false |
Enable crypto registration |
systemName |
Yes | '' |
Name of the system in Crypto API |
systemType |
No | 'webapp' |
System type (console, windowsservice, webapp, guidewire, desktopapp, script, other) |
allowedSystems |
No | [] |
Additional Crypto systems (name and type) that can decrypt the keys. The pipeline attempts to revoke every other system on deploy; skipped or failed revocations are reported as warnings |
Allow Additional Callers to Retrieve the Keys¶
Only the system named in systemName can decrypt the keys by default. A legacy caller computes its system hash from its own ApplicationName and SystemType, so a caller with a different name is denied. List each such caller in allowedSystems and the pipeline grants it access to every registered cipher on every deployment, creating the Crypto system if it does not exist.
Name and Type Must Match the Caller
name is case-sensitive and must equal the caller's ApplicationName. type must equal the SystemType the caller passes to ComputeHash.
Review Entries Carefully
The system hash is derived from the system name and type, and the Crypto API does not verify that the caller is that application. Anyone on the internal network who knows a listed name can read the keys. Keep the list minimal and have each addition reviewed in the pull request.
Revoke Access¶
The list is the full set of allowed callers. On every deployment the pipeline removes any system from the keys' ciphers that is not systemName or an allowedSystems entry, so deleting an entry revokes that caller at the next deploy.
- An empty or missing
allowedSystemsrevokes every system exceptsystemName. - A system name shared by more than one system is skipped with a warning, because the API lists names, not hashes.
- Revoked systems are never deleted. If one is left with no ciphers, the run logs a warning naming it so the team can consider cleaning it up if it is unused.
- Skipped or failed revocations, and a failed Environment API refresh, mark the run as succeeded with issues.
Check Existing Access Before the First Deploy
The first deploy also removes access that was granted by hand, for example by Architecture. Add any caller that still needs the keys to allowedSystems first.
See Settings and Secrets for full details on the secretsVariableGroupName parameter and the [ENV] naming convention.
Step 4: Deploy¶
Commit and push your changes. The pipeline:
- Loads keys from the variable group (filtered by environment)
- Passes them to Terraform via
application_secrets - Creates the APIM subscription with your keys
- Sets
subscription_required = trueon the APIM API - Applies the subscription key policy (no JWT validation)
If crypto registration is enabled, the pipeline additionally:
- Creates or updates a Crypto system for your application
- Registers each key as an encrypted cipher in the Crypto API
- Stores the cipher IDs as secure settings in the Environment Service
- Stores the API base URL (the Terraform
api_urloutput) as the non-secureapi_base_urlsetting - Grants each
allowedSystemsentry access to the ciphers - Revokes every other system from the ciphers and warns about systems left without ciphers
- Refreshes every Environment API instance, like Refresh Environment in EnvironmentBoss, so callers get the new settings immediately
When the variable group holds the same key at several scopes, the pipeline registers the one Terraform uses: [<environment>] first (for example [QA]), then [<environment short name>], then [GLOBAL].
Settings are stored under:
- Track: mapped from the pipeline environment (
platformdev/test→enttest1,qa→np13,uat→np16,prod→prod) - Setting group: your
projectId - Keys:
primary_subscription_key,secondary_subscription_key(secure),api_base_url(non-secure)
You can verify the registered settings in EnvironmentBoss.
Step 5: Call the API¶
Legacy callers must send the subscription key in the Ocp-Apim-Subscription-Key header through Front Door:
GET https://app-int-{environment}.saif.com/api/exp/{app-name}/{route}
Ocp-Apim-Subscription-Key: {your-subscription-key}
Retrieving Keys via Environment Service¶
If crypto registration is enabled, legacy .NET callers can retrieve the decrypted subscription key using the Environment Client and System Hash Service.
Required NuGet package (from the SAIF internal feed):
This package provides IEnvironmentClient, ISystemHashService, and SystemType. Register both services in your DI container and inject them into the class that needs to retrieve keys:
public class SubscriptionKeyProvider
{
private readonly IEnvironmentClient _environmentClient;
private readonly ISystemHashService _systemHashService;
public SubscriptionKeyProvider(
IEnvironmentClient environmentClient,
ISystemHashService systemHashService)
{
_environmentClient = environmentClient;
_systemHashService = systemHashService;
}
public string GetPrimaryKey()
{
// Compute time-sensitive system hash
var hash = _systemHashService.ComputeHash(
SystemType.WebApp, _environmentClient.ApplicationName);
// Retrieve decrypted key — returns the original subscription key value
return _environmentClient.GetSecureSetting(
"primary_subscription_key",
"your-project-id", // setting group = projectId
hash);
}
}
System Hash Timeout
The system hash is time-sensitive (~90 second window). Compute the hash immediately before each GetSecureSetting call.
Finding the API Base URL¶
The pipeline also publishes the API's base URL so callers do not hard-code a host per environment. It is stored as the plain-text api_base_url setting in the same track and setting group (projectId) as the keys. The value is the Terraform api_url output, which is the external host when the API is external.
- Unlike the keys,
api_base_urlis not secure, so no system hash is needed to read it. - The setting is written on every deploy. If the
api_urloutput is empty, the write is skipped with a warning. - Verify the value in EnvironmentBoss by searching for
key:api_base_urlwith yourprojectIdas the group.
Event services follow the same pattern and publish their event_url output as api_base_url.
The pipeline reads the URL from the api_url (APIs) or event_url (event services) Terraform output, so the output must exist. Newly generated projects include it. Existing projects must add it; see Terraform output event_url, api_url, or app_url not found.
Key Rotation¶
To rotate subscription keys without downtime:
- Generate a new key value
- Update the
secondary_keyentry in your variable group with the new value - Deploy — APIM and Crypto/Environment Service are updated with the new secondary key
- Distribute the secondary key to all callers
- Once callers have switched, swap: move the new value to
primary_key, generate another forsecondary_key - Deploy again to finalize
Troubleshooting¶
401 SubscriptionKeyInvalid¶
| Cause | Solution |
|---|---|
| Wrong key value | Verify the key matches what's in your variable group for the target environment |
| Missing header | Ensure Ocp-Apim-Subscription-Key header is present and not empty |
| Key not deployed | Confirm the pipeline ran successfully after adding keys to the variable group |
403 Header X-Azure-FDID Not Found¶
| Cause | Solution |
|---|---|
| Calling APIM directly | Requests must go through Front Door, not directly to APIM |
500 BackendConnectionFailure¶
| Cause | Solution |
|---|---|
| Backend app not deployed | Deploy your application before testing |
| Mock backend not configured | Send x-mocking: false header to route to the real backend |
Crypto Registration Failures¶
| Cause | Solution |
|---|---|
primary_key not found in application_secrets |
Add [ENV]primary_key entries to your variable group |
Unknown environment |
Verify DeploymentEnvironmentShortName maps to a known track |
| Crypto API timeout | The Crypto API may need a warm-up — the pipeline retries automatically |
allowedSystems entries need a name and a type |
Give every entry a name and one of the supported type values |
Caller gets unauthorized from GetSecureSetting |
Add the caller to allowedSystems with the exact ApplicationName and SystemType it hashes with, then redeploy |
Environment API refresh failed warning |
The Environment API may be down, so callers can read stale settings. Refresh manually in EnvironmentBoss |
Skipping '<name>' or Failed to revoke '<name>' warning |
That system still has access to the keys. Ask the Crypto API owners to remove it, or add it to allowedSystems if it should keep access |
no longer have any ciphers warning |
The listed systems no longer decrypt anything. Consider cleaning them up if they are not needed |
GetSecureSetting Fails for a Specific On-Prem Track¶
For the symptom, cause, and fix when GetSecureSetting can't find the subscription key for a specific on-prem track (for example np13) while it works for another, see Subscription key missing in EnvironmentBoss for an environment.
📚 Related Documentation¶
- Settings and Secrets - Variable group setup and the
[ENV]naming convention - Event Service - Same variable group pattern for event service keys
- Authorization Concepts - Scopes, roles, and JWT-based auth
- App Permissions - Standard OAuth app-to-app authorization
- Filevine Webhook Integration - Filevine-specific policy type