API Authentication Policy
General Information
Policy Type
policy-api-authentication
Description
API Authentication policy adds authentication credentials to outgoing requests to target APIs. It supports BASIC, BASE64, DIGEST, and API authentication types, and can send credentials via headers, parameters, body message, or body injection. This policy enables Apinizer to authenticate with backend APIs on behalf of clients.
Endpoints
List Policies
GET /apiops/projects/{projectName}/apiProxies/{apiProxyName}/policies/
Add Policy
POST /apiops/projects/{projectName}/apiProxies/{apiProxyName}/policies/{policyName}/
Update Policy
PUT /apiops/projects/{projectName}/apiProxies/{apiProxyName}/policies/{policyName}/
Delete Policy
DELETE /apiops/projects/{projectName}/apiProxies/{apiProxyName}/policies/{policyName}/
List Policies
Endpoint
GET /apiops/projects/{projectName}/apiProxies/{apiProxyName}/policies/
Request
Headers
| Header | Value |
|---|---|
| Authorization | Bearer {token} |
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| projectName | string | Yes | Project name |
| apiProxyName | string | Yes | API Proxy name |
Response
Success Response (200 OK)
{
"status": "SUCCESS",
"resultList": [
{
"apiProxy": {
"name": "MyAPI",
"requestPolicyList": [
{
"type": "policy-api-authentication",
"name": "api-auth-policy",
"description": "Authenticate with backend API",
"active": true,
"authType": "BASIC",
"sendType": "HEADER",
"usernameFieldName": "X-Username",
"passwordFieldName": "X-Password",
"messageContentType": "XML"
}
],
"responsePolicyList": [],
"errorPolicyList": []
}
}
],
"resultCount": 1
}
Note: In list operations, passwords in apiAuthCondExpressionList are cleared for security.
cURL Example
curl -X GET \
"https://demo.apinizer.com/apiops/projects/MyProject/apiProxies/MyAPI/policies/" \
-H "Authorization: Bearer YOUR_TOKEN"
Add Policy
Endpoint
POST /apiops/projects/{projectName}/apiProxies/{apiProxyName}/policies/{policyName}/
Request
Headers
| Header | Value |
|---|---|
| Authorization | Bearer {token} |
| Content-Type | application/json |
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| projectName | string | Yes | Project name |
| apiProxyName | string | Yes | API Proxy name |
| policyName | string | Yes | Policy name |
Request Body
Full JSON Body Example - BASIC Authentication with HEADER
{
"operationMetadata": {
"targetScope": "ALL",
"targetPipeline": "REQUEST",
"deploy": true,
"deployTargetEnvironmentNameList": ["tester"],
"order": 1
},
"policy": {
"type": "policy-api-authentication",
"description": "Basic authentication via header",
"active": true,
"authType": "BASIC",
"sendType": "HEADER",
"usernameFieldName": "X-Username",
"passwordFieldName": "X-Password",
"messageContentType": "XML",
"apiAuthCondExpressionList": [
{
"id": 1,
"username": "api-user",
"password": "api-password",
"policyCondition": null
}
]
}
}
Full JSON Body Example - BASE64 Authentication with PARAM
{
"operationMetadata": {
"targetScope": "ALL",
"targetPipeline": "REQUEST",
"deploy": true,
"deployTargetEnvironmentNameList": ["production"],
"order": 1
},
"policy": {
"type": "policy-api-authentication",
"description": "Base64 authentication via parameter",
"active": true,
"authType": "BASE64",
"sendType": "PARAM",
"passwordFieldName": "token",
"messageContentType": "XML",
"apiAuthCondExpressionList": [
{
"id": 1,
"username": "api-user",
"password": "api-password",
"policyCondition": null
}
]
}
}
Full JSON Body Example - DIGEST Authentication with HEADER
{
"operationMetadata": {
"targetScope": "ALL",
"targetPipeline": "REQUEST",
"deploy": true,
"deployTargetEnvironmentNameList": ["production"],
"order": 1
},
"policy": {
"type": "policy-api-authentication",
"description": "Digest authentication via header",
"active": true,
"authType": "DIGEST",
"sendType": "HEADER",
"usernameFieldName": "X-Username",
"passwordFieldName": "X-Password",
"createdFieldName": "X-Created",
"nonceFieldName": "X-Nonce",
"messageContentType": "XML",
"apiAuthCondExpressionList": [
{
"id": 1,
"username": "api-user",
"password": "api-password",
"policyCondition": null
}
]
}
}
Full JSON Body Example - BODY_MESSAGE Send Type
{
"operationMetadata": {
"targetScope": "ALL",
"targetPipeline": "REQUEST",
"deploy": true,
"deployTargetEnvironmentNameList": ["production"],
"order": 1
},
"policy": {
"type": "policy-api-authentication",
"description": "Authentication via body message",
"active": true,
"authType": "BASIC",
"sendType": "BODY_MESSAGE",
"messageContentType": "JSON",
"bodyMessage": "{\n \"credentials\": {\n \"username\": \"${username}\",\n \"password\": \"${password}\"\n }\n}",
"bodyMessageInjectionPath": "$.auth",
"apiAuthCondExpressionList": [
{
"id": 1,
"username": "api-user",
"password": "api-password",
"policyCondition": null
}
]
}
}
Full JSON Body Example - BODY_INJECTION Send Type
{
"operationMetadata": {
"targetScope": "ALL",
"targetPipeline": "REQUEST",
"deploy": true,
"deployTargetEnvironmentNameList": ["production"],
"order": 1
},
"policy": {
"type": "policy-api-authentication",
"description": "Authentication via body injection",
"active": true,
"authType": "BASIC",
"sendType": "BODY_INJECTION",
"messageContentType": "JSON",
"usernameFieldName": "username",
"passwordFieldName": "password",
"usernameInjectionPath": "$.auth.username",
"passwordInjectionPath": "$.auth.password",
"apiAuthCondExpressionList": [
{
"id": 1,
"username": "api-user",
"password": "api-password",
"policyCondition": null
}
]
}
}
Full JSON Body Example - Using authApiName
{
"operationMetadata": {
"targetScope": "ALL",
"targetPipeline": "REQUEST",
"deploy": true,
"deployTargetEnvironmentNameList": ["production"],
"order": 1
},
"policy": {
"type": "policy-api-authentication",
"description": "Authentication using API name",
"active": true,
"authApiName": "auth-api-name",
"messageContentType": "XML"
}
}
Note: authApiName is currently used directly as API ID. Name to ID conversion will be implemented in a future release.
Request Body Fields
operationMetadata
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| targetScope | string | Yes | - | Policy scope: ALL or ENDPOINT |
| targetEndpoint | string | No* | - | Endpoint path (required if targetScope=ENDPOINT) |
| targetEndpointHTTPMethod | string | No* | - | HTTP method (required if targetScope=ENDPOINT) |
| targetPipeline | string | Yes | - | Pipeline: REQUEST, RESPONSE, or ERROR |
| deploy | boolean | No | true | Whether to deploy after adding policy |
| deployTargetEnvironmentNameList | array | No | [] | List of environment names to deploy to |
| order | integer | No | null | Policy execution order (starts from 1) |
Enum: targetScope
ALL- Policy applies to all endpointsENDPOINT- Policy applies only to specified endpoint
Enum: targetPipeline
REQUEST- Executes in request pipeline (adds authentication to request)RESPONSE- Executes in response pipelineERROR- Executes in error pipeline
Enum: targetEndpointHTTPMethod
GET,POST,PUT,DELETE,PATCH,OPTIONS,HEAD
policy
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| type | string | Yes | - | Policy type: policy-api-authentication |
| description | string | No | - | Policy description |
| active | boolean | No | true | Whether policy is active |
| authType | string | No* | - | Authentication type (required if using conditional expressions) |
| sendType | string | No* | - | Send type (required if using conditional expressions) |
| messageContentType | string | No | XML | Message content type: XML, JSON, or ALL_BODY |
| usernameFieldName | string | No* | - | Username field name (required for BASIC/DIGEST with HEADER/PARAM, BODY_INJECTION) |
| passwordFieldName | string | No* | - | Password field name (required for BASIC/BASE64/DIGEST with HEADER/PARAM, BODY_INJECTION) |
| createdFieldName | string | No* | - | Created timestamp field name (required for DIGEST with HEADER/PARAM) |
| nonceFieldName | string | No* | - | Nonce field name (required for DIGEST with HEADER/PARAM) |
| bodyMessage | string | No* | - | Body message template (required for BODY_MESSAGE send type) |
| bodyMessageInjectionPath | string | No* | - | Body message injection path (required for BODY_MESSAGE send type) |
| usernameInjectionPath | string | No* | - | Username injection path (required for BODY_INJECTION send type) |
| passwordInjectionPath | string | No* | - | Password injection path (required for BODY_INJECTION send type) |
| createdInjectionPath | string | No | - | Created timestamp injection path (for DIGEST with BODY_INJECTION) |
| nonceInjectionPath | string | No | - | Nonce injection path (for DIGEST with BODY_INJECTION) |
| authApiName | string | No* | - | Authentication API name (alternative to conditional expressions) |
| apiAuthCondExpressionList | array | No* | [] | List of conditional authentication expressions (required if authApiName not provided) |
EnumPolicyApiAuthenticationAuthType
BASIC- Plain text username/password authenticationBASE64- Base64 encoded authenticationDIGEST- HTTP Digest authenticationAPI- API-based authentication
EnumPolicyApiAuthenticationSendType
HEADER- Send credentials via HTTP headersPARAM- Send credentials via query/path parametersBODY_MESSAGE- Send credentials via body message templateBODY_INJECTION- Inject credentials into existing body