Contact Us 1-800-596-4880

Credential Injection API Key Policy

Policy Name

Credential Injection API Key

Summary

Injects an API key or client credentials headers into outgoing requests

Category

Security

First Omni Gateway version available

v1.10.2

Release Notes

Credential Injection API Key

Returned Status Codes

No return codes exist for this policy. Error codes are returned from the upstream service.

Summary

The Credential Injection API Key policy injects authentication credentials into upstream requests to authenticate with upstream services that require API key or client credential authentication. The policy supports two authentication types:

  • API Key: Injects an API key value into the Authorization header or a custom header.

  • Client ID and Secret: Injects the client ID and client secret value into the client_id and client_secret headers or custom headers.

Payload Handling

The Credential Injection API Key policy processes only requests. Responses pass through unchanged.

How the policy handles the request body depends on authType and apiKeyType:

  • clientCredentials: The policy reads headers only and doesn’t buffer the request body.

  • apiKey with apiKeyType set to static (the default): The policy reads headers only and doesn’t buffer the request body.

  • apiKey with apiKeyType set to expression: The policy buffers the full request body only when the DataWeave expression in apiKeySelector can’t be resolved from attributes at runtime (for example, when the branch that’s taken references payload).

Buffered payloads count toward the Omni Gateway payload limit, which is 1 MB by default. To change the limit on a self-managed Omni Gateway, set the FLEX_DOWNSTREAM_CONNECTION_BUFFER_LIMIT_BYTES environment variable. In Connected Mode, you can also set Global connection buffer limit in Runtime Manager. For more information, see Configure Global and Routing Settings in Runtime Manager. For more information about the limit, see Omni Gateway Limits and Performance Metrics.

To avoid buffering, use a static API key or an expression that references only attributes.

Configuring Policy Parameters

Omni Gateway Local Mode

When you apply the policy via declarative configuration files, Refer to the following policy definition and table of parameters:

- policyRef:
    name: credential-injection-api-key-flex
  config:
    authType: <string> // REQUIRED
    overwrite: <boolean> // REQUIRED, default: true
    headersToRemove: <array> // OPTIONAL
    # For API Key authentication:
    apiKeyType: <string> // OPTIONAL when authType is "apiKey", default: static
    apiKey: <string> // REQUIRED when apiKeyType is "static"
    apiKeySelector: <dataweave> // REQUIRED when apiKeyType is "expression"
    customHeader: <string> // OPTIONAL when authType is "apiKey"
    # For Client Credentials authentication:
    clientId: <string> // REQUIRED when authType is "clientCredentials"
    clientSecret: <string> // REQUIRED when authType is "clientCredentials"
    customClientIdHeader: <string> // OPTIONAL when authType is "clientCredentials"
    customClientSecretHeader: <string> // OPTIONAL when authType is "clientCredentials"
Parameter Required or Optional Default Value Description

authType

Required

apiKey

Authentication type to inject, either apiKey or clientCredentials.

overwrite

Required

true

Overwrite authentication headers if present in the request.

headersToRemove

Optional

[]

Names of request headers to remove before the policy injects credentials. Header names are case-insensitive. For clientCredentials, if you list either the client ID header or the client secret header, the policy injects both headers, even when overwrite is false.

apiKeyType

Optional

static

How the policy gets the API key when authType is apiKey: static uses the value in apiKey, and expression resolves the value at runtime from apiKeySelector.

apiKey

Required when apiKeyType is static.

N/A

The static API key value to inject.

apiKeySelector

Required when apiKeyType is expression.

N/A

A DataWeave expression that resolves the API key at runtime. The expression can use attributes and payload. The expression must resolve to a non-empty string, and the policy trims leading and trailing whitespace from the result. For example: #[attributes.headers['x-api-key']]. The policy ignores this field unless apiKeyType is expression.

customHeader

Optional

N/A

Use a custom header name instead of Authorization for API key injection.

clientId

Required when authType is clientCredentials.

N/A

The client ID to inject.

clientSecret

Required when authType is clientCredentials.

N/A

The client secret to inject.

customClientIdHeader

Optional

N/A

Use a custom header instead of client_id for client ID injection.

customClientSecretHeader

Optional

N/A

Use a custom header instead of client_secret for client secret injection.

Anypoint API Manager shows the Headers to remove, API Key Type, and API Key Expression fields (headersToRemove, apiKeyType, and apiKeySelector) for every Omni Gateway version, but the policy ignores them in Omni Gateway 1.13.0 through 1.13.8 and 1.14.0 through 1.14.4. To use these fields, update Omni Gateway to the latest patch release of your version.

Resource Configuration Examples

  • API Key:

    - policyRef:
        name: credential-injection-api-key-flex
      config:
        authType: apiKey
        apiKey: my-secret-api-key
        overwrite: true
  • API Key from a DataWeave expression:

    - policyRef:
        name: credential-injection-api-key-flex
      config:
        authType: apiKey
        apiKeyType: expression
        apiKeySelector: "#[attributes.headers['x-api-key']]"
        overwrite: true
  • API Key with Custom Header:

    - policyRef:
        name: credential-injection-api-key-flex
      config:
        authType: apiKey
        apiKey: my-secret-api-key
        customHeader: X-API-Key
        overwrite: false
  • Client Credentials:

    - policyRef:
        name: credential-injection-api-key-flex
      config:
        authType: clientCredentials
        clientId: my-client-id
        clientSecret: my-client-secret
        overwrite: true
  • Client Credentials with Custom Headers:

    - policyRef:
        name: credential-injection-api-key-flex
      config:
        authType: clientCredentials
        clientId: my-client-id
        clientSecret: my-client-secret
        customClientIdHeader: X-Client-ID
        customClientSecretHeader: X-Client-Secret
        overwrite: false

Managed Omni Gateway and Omni Gateway Connected Mode

When you apply the policy from the UI, the following parameters are displayed:

Parameter Description

Authentication Type

Type of authentication header to inject: API Key or Client ID and Secret.

Overwrite headers

Overwrite authentication headers if present in the request.

Headers to remove

Names of request headers to remove before the policy injects credentials. Header names are case-insensitive. For client credentials, if you list either the client ID header or the client secret header, the policy injects both headers, even when Overwrite headers is disabled.

API Key Type

How the policy gets the API key: Static or DataWeave Expression.

API Key

The static API key value to inject. Required when API Key Type is Static.

API Key Expression

A DataWeave expression that resolves the API key at runtime. Required when API Key Type is DataWeave Expression.

Custom header

Use a custom header instead of Authorization for API key injection.

Client ID

The client ID to inject.

Client Secret

The client secret to inject.

Custom Client ID header

Use a custom header instead of client_id for client ID injection.

Custom Client secret header

Use a custom header instead of client_secret for client secret injection.