简体   繁体   English

在 API Header 中创建参数 WSO2

[英]Create parameters in API Header in WSO2

I have created a API in WSO2 studio integrator like below:我在 WSO2 工作室集成器中创建了一个 API,如下所示:

curl --location --request POST 'http://localhost:8290/internal/send-messages' curl --location --request POST 'http://localhost:8290/internal/send-messages'
--header 'accept: text/plain' --header '接受:文本/纯文本'
--header 'Content-Type: application/json' --header 'Content-Type: application/json'
--data-raw '{ "bankName": "heere", "uniqueIdentifier": "445334564" }' --data-raw '{ "bankName": "heere", "uniqueIdentifier": "445334564" }'

To pass the requests (which received from this API) toward the endpoint, I need to add two following parameters into API Header要将请求(从该 API 接收到)传递到端点,我需要将以下两个参数添加到 API Header

--header 'MasterName: TOMSON' --header 'MasterName: TOMSON'
--header 'clientName: TOM' \ --header 'clientName: TOM' \

TOMSON value is unique(static) and would NOT change for any user. TOMSON 值是唯一的(静态的)并且不会因任何用户而改变。 However TOM would be change based on application username given from API Manager (there is OATH2 authentication).然而,TOM 将根据 API Manager 提供的应用程序用户名进行更改(有 OATH2 身份验证)。

  1. How can I add a static header (Like MasterName) to a API while sending toward the endpoint如何在向端点发送时将 static header(如 MasterName)添加到 API

  2. How can I understand the username of application??我如何理解应用程序的用户名?

  1. You can add a static header using the header mediator[1].您可以使用 header 中介 [1] 添加 static header。
    <header name="MasterName" value="TOMSON" scope="transport"/>

  2. To get the application information from the API Manager, you can enable backend JWT[2].要从 API Manager 获取应用程序信息,您可以启用后端 JWT[2]。 This will be a JWT generated with much more information regarding the request.这将是一个 JWT,其中包含有关该请求的更多信息。 By decoding this[3] JWT at the backend, you can get the application information with the claim http://wso2.org/claims/applicationname .通过在后端解码这个[3] JWT,可以得到声明为http://wso2.org/claims/applicationname的应用信息。

[1] - https://ei.docs.wso2.com/en/latest/micro-integrator/references/mediators/header-Mediator/ [1] - https://ei.docs.wso2.com/en/latest/micro-integrator/references/mediators/header-Mediator/
[2] - https://apim.docs.wso2.com/en/latest/deploy-and-publish/deploy-on-gateway/api-gateway/passing-enduser-attributes-to-the-backend-via-api-gateway/ [2] - https://apim.docs.wso2.com/en/latest/deploy-and-publish/deploy-on-gateway/api-gateway/passing-enduser-attributes-to-the-backend-via- api网关/
[3] - WSO2 Decode JWT [3] - WSO2 解码JWT

You can use header mediator to add headers您可以使用header 调解器添加标头

For example例如

<header name="miCustomHeader" value="ThisIsTheWay" scope="transport"/>

<send>
    <endpoint>
        <address uri="https://someRandomURL"/>
    </endpoint>
</send>

It will send miCustomHeader along its value to the endpoint它会将miCustomHeader及其值发送到端点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM