設定OAuth 2.0驗證 custom-channel-oauth2

在此頁面上:​瞭解如何在Adobe Journey Optimizer中設定自訂管道的OAuth 2.0驗證,包括權杖要求承載、認證路徑、權杖擷取和傳遞要求中的權杖位置。

當您在建立自訂通道時選取​ OAuth 2.0 ​作為驗證型別時,請設定Adobe Journey Optimizer用來從您的授權伺服器擷取存取權杖的權杖要求。

Journey Optimizer使用endpoint、method、request和policy設定來傳送Token要求。 然後它使用tokenPath從回應中擷取存取權杖,並使用locationConfig將其新增至傳遞要求。

OAuth 2.0驗證裝載會設定對​ 權杖端點 ​的要求。 它與傳送至您自訂通道傳遞端點的訊息裝載不同。

設定權杖請求 token-request

使用以下範例來設定您的Token要求。 將範例端點和認證值取代為您的授權伺服器所需的值。 範例中的headers和queryParams專案是選用專案:如果您的權杖端點不需要它們,請移除它們,並從credentialPaths移除相符的專案。

表單本文範例 form-body-example

當權杖端點預期表單欄位(例如grant_type、client_id或client_secret)時,請使用form裝載。

{
  "type": "oauth2",
  "endpoint": {
    "uri": "https://auth.example.com/oauth/token"
  },
  "method": "post",
  "request": {
    "headers": [
      {
        "key": "sampleHeaderKey",
        "value": "sampleHeaderValue"
      }
    ],
    "queryParams": [
      {
        "key": "sampleQueryParamKey",
        "value": "sampleQueryParamValue"
      }
    ],
    "payload": {
      "type": "form",
      "content": [
        {
          "key": "grant_type",
          "value": "client_credentials"
        },
        {
          "key": "client_id",
          "value": "your-client-id"
        },
        {
          "key": "client_secret",
          "value": "your-client-secret"
        }
      ],
      "includeNullValues": false
    }
  },
  "response": {
    "type": "json"
  },
  "policy": {
    "timeoutInMilliseconds": 30000,
    "cache": {
      "enabled": true,
      "ttlInSeconds": 300
    },
    "retry": {
      "enabled": false,
      "maxRetryCount": 3
    }
  },
  "credentialPaths": [
    "header.sampleHeaderKey",
    "queryParam.sampleQueryParamKey",
    "payload.client_id",
    "payload.client_secret"
  ],
  "tokenPath": "access_token",
  "locationConfig": {
    "key": "Authorization",
    "location": "header"
  }
}

對於form裝載,每個認證路徑都使用表單欄位金鑰,例如payload.client_secret。 認證路徑中不包含content或陣列索引。

JSON內文範例 json-body-example

當權杖端點需要JSON要求內文時,請使用json裝載。

{
  "type": "oauth2",
  "endpoint": {
    "uri": "https://auth.example.com/oauth/token"
  },
  "method": "post",
  "request": {
    "headers": [
      {
        "key": "sampleHeaderKey",
        "value": "sampleHeaderValue"
      }
    ],
    "queryParams": [
      {
        "key": "sampleQueryParamKey",
        "value": "sampleQueryParamValue"
      }
    ],
    "payload": {
      "type": "json",
      "content": {
        "grant_type": "client_credentials",
        "client_id": "your-client-id",
        "client_secret": "your-client-secret"
      },
      "includeNullValues": false
    }
  },
  "response": {
    "type": "json"
  },
  "policy": {
    "timeoutInMilliseconds": 30000,
    "cache": {
      "enabled": true,
      "ttlInSeconds": 300
    },
    "retry": {
      "enabled": false,
      "maxRetryCount": 3
    }
  },
  "credentialPaths": [
    "header.sampleHeaderKey",
    "queryParam.sampleQueryParamKey",
    "payload.client_id",
    "payload.client_secret"
  ],
  "tokenPath": "access_token",
  "locationConfig": {
    "key": "Authorization",
    "location": "header"
  }
}

Oauth 2.0欄位 oauth2-fields

欄位
說明
type
必須為oauth2。
endpoint.uri
Oauth 2.0權杖端點的HTTPS URL。
method
用於呼叫權杖端點的HTTP方法。 使用post進行Token要求。
request.headers
傳送至權杖端點的選用標頭。
request.queryParams
附加至權杖端點URL的可選查詢引數。
request.payload
權杖要求內文。 支援form和json裝載。
request.payload.includeNullValues
定義權杖要求內文中是否包含具有null值的欄位。
response.type
回應格式。 當權杖端點傳回JSON回應時使用json。
policy.timeoutInMilliseconds
等候權杖端點回應的最長時間。
policy.cache
定義是否快取OAuth權杖及其時長。
policy.retry
權杖端點失敗的可選重試設定。
credentialPaths
請求包含認證之欄位的路徑。 這些欄位會被視為憑證,而且可以安全地管理。
tokenPath
OAuth回應中存取權杖的點分隔路徑,例如access_token或data.access_token。
locationConfig
定義將擷取的Token新增至傳遞請求的位置。
locationConfig.key
攜帶權杖的標頭或查詢引數的名稱,例如Authorization。
locationConfig.location
新增權杖的位置: header或queryParam。

當權杖快取啟用時,Journey Optimizer會在設定的快取期間內重複使用OAuth權杖,而不是針對每個傳送請求呼叫權杖端點。

識別認證欄位 credential-paths

使用credentialPaths識別哪些要求欄位包含認證。 如果標頭或查詢引數包含認證,請將其路徑以及任何認證路徑納入請求內文中。 上述範例將範例標題和查詢引數值識別為認證;調整此清單以符合您的請求。

前置詞
用於
範例
header.
要求標頭中傳遞的認證。
header.sampleHeaderKey
queryParam.
傳入查詢引數的認證。
queryParam.sampleQueryParamKey
payload.
要求內文中傳遞的認證。
payload.client_secret

套用下列規則:

  • 路徑必須以header、queryParam或payload開頭,並使用點做為分隔符號。
  • 對於form承載,請使用payload.<formFieldKey>。
  • 對於json負載,請使用JSON物件路徑,例如payload.client_id或payload.credentials.client_secret。 不要在路徑中包含content。
  • 不支援空白路徑區段。 例如,payload..client_id無效。

對於巢狀JSON內文,請使用此設定摘要中所示的點標籤法:

{
  "request": {
    "payload": {
      "type": "json",
      "content": {
        "credentials": {
          "client_id": "your-client-id",
          "client_secret": "your-client-secret"
        }
      },
      "includeNullValues": false
    }
  },
  "credentialPaths": [
    "payload.credentials.client_id",
    "payload.credentials.client_secret"
  ]
}

擷取存取權杖 token-path

tokenPath定義存取權杖在OAuth 2.0權杖回應中的位置。

針對下列回應,將tokenPath設為access_token:

{
  "access_token": "example-access-token",
  "token_type": "Bearer",
  "expires_in": 3600
}

針對巢狀回應,將tokenPath設為data.access_token:

{
  "data": {
    "access_token": "example-access-token"
  }
}

將權杖新增至傳遞請求 token-location

locationConfig會定義Journey Optimizer在呼叫自訂通道傳遞端點時新增擷取的Token的位置。

若要在Authorization標頭中傳送Token,請使用:

{
  "locationConfig": {
    "key": "Authorization",
    "location": "header"
  }
}
位置
說明
header
將權杖新增為HTTP標頭。
queryParam
將代號新增為查詢引數。

限制和驗證規則 limits

欄位
限制
endpoint.uri
必須是具有非空白主機的絕對HTTPS URL。 最大長度:2048個字元。
policy.timeoutInMilliseconds
最小:300毫秒。 最大: 60000毫秒。
policy.cache.ttlInSeconds
適用於啟用快取時。 最短:300秒。 上限: 3600秒。
request.headers
最多50個標頭。 標題索引鍵長度: 1-100個字元。 標頭值上限: 8192個字元。
request.queryParams
最多50個查詢引數。 查詢引數金鑰長度: 1-100個字元。 查詢引數值上限: 8192個字元。
request.payload.type=form
最多50個表單欄位。 表單金鑰長度: 1-100個字元。 不允許重複的表單索引鍵。
認證值
1-1024個字元。
tokenPath
必須為有效的點分隔路徑。 只有當整個回應都是Token時,才允許空白值。
credentialPaths
必須以header、queryParam或payload開頭,並使用點做為分隔符號。

後續步驟 next-steps

AI Knowledge Reference

This section contains structured knowledge intended to support interpretation, retrieval, and question answering related to this topic.

For complete understanding, this information should be combined with the documentation on this page. Neither source is intended to stand alone; the page describes the feature, while this section provides additional context that helps disambiguate terminology, intent, applicability, and constraints.

  • TL;DR: Configure OAuth 2.0 authentication for a custom channel by defining the token endpoint request, identifying credential fields, extracting the access token from the response, and specifying where to add it to delivery requests.

Intents:

  • Configure OAuth 2.0 authentication when creating a custom channel or managing API credentials
  • Choose a form or JSON body for the token endpoint request
  • Identify credential fields in headers, query parameters, and request bodies
  • Extract an access token from a top-level or nested response field
  • Add the retrieved token to a delivery request header or query parameter
  • Understand token caching and authentication configuration limits

Glossary:

  • Token endpoint: The authorization server endpoint that Journey Optimizer calls to retrieve an access token
  • Authentication payload: The configuration of the OAuth 2.0 token request, separate from the message payload sent to the delivery endpoint (product-specific)
  • Credential paths: The paths identifying request fields that contain credentials, configured through credentialPaths (product-specific)
  • Token path: The dot-separated path to the access token in the token endpoint response, configured through tokenPath (product-specific)
  • Token location configuration: The delivery request header or query parameter to which the retrieved token is added, configured through locationConfig (product-specific)

Guardrails:

  • Set the authentication configuration type to oauth2 and use post for token requests.
  • The token endpoint must be an absolute HTTPS URL with a non-empty host and a maximum length of 2048 characters.
  • Token request bodies support form and json payloads; choose the format expected by your authorization server.
  • Credential paths must start with header, queryParam, or payload, use dots as separators, and contain no empty path segments.
  • Form credential paths use the form field key. JSON credential paths use the JSON object path. Do not include content or form array indexes in credential paths.
  • Supported token locations are header and queryParam.
  • The token endpoint timeout must be between 300 and 60000 milliseconds.
  • When token caching is enabled, the cache duration must be between 300 and 3600 seconds. Journey Optimizer reuses the token for the configured duration instead of retrieving a token for every delivery request.
  • Credential values must contain between 1 and 1024 characters.
  • An empty tokenPath is allowed only when the entire response is the token.

Terminology:

  • Canonical name: OAuth 2.0 authentication - variants: OAuth 2.0 authentication payload, OAuth token request configuration
  • Do not confuse: “authentication payload” (configuration for retrieving an access token) with “message payload” (content sent to the custom channel delivery endpoint)
  • Do not confuse: credentialPaths (credential fields in the token request) with tokenPath (access token field in the token response)
  • Do not confuse: request.headers and request.queryParams (values sent to the token endpoint) with locationConfig (where the retrieved token is added to delivery requests)

FAQ:

  • Q: When should I use a form or JSON payload? - Use form when the token endpoint expects form fields, and json when it expects a JSON request body.
  • Q: How do I identify a client secret in a form body? - Use the form field key, for example, payload.client_secret, without content or an array index.
  • Q: How do I identify credentials in a nested JSON body? - Use dot notation, for example, payload.credentials.client_secret.
  • Q: How do I extract a token from a nested response? - Set tokenPath to the response field path, for example, data.access_token.
  • Q: Where can Journey Optimizer add the token to delivery requests? - Set locationConfig.location to header or queryParam and locationConfig.key to the header or query parameter name.
  • Q: Does Journey Optimizer retrieve a token for every delivery request? - When caching is enabled, it reuses the token for the configured cache duration.
recommendation-more-help
journey-optimizer-help