简体   繁体   English

WSO2 API Manager 1.9-附加固定的标头信息

[英]WSO2 API Manager 1.9 - Append fixed header information

I need to append a fixed Authorization header to an API endpoint. 我需要将固定的Authorization标头附加到API端点。 This is an application specific token for my endpoint system so I do not need API subscribers to enter this information nor want them in the know. 这是我的端点系统的特定于应用程序的令牌,因此我不需要API订阅者来输入此信息,也不需要他们知道。

An almost similar question was raised before but hasn't been answered. 之前提出了一个几乎类似的问题 ,但尚未得到回答。 The documentation here doesn't provide specific details and is a bit obscure so I am lost on how to achieve this. 这里的文档没有提供具体细节,而且有点晦涩难懂,所以我迷失于如何实现这一点。 Has anybody done this? 有人这样做吗?

Appreciate any help, cheers! 感谢您的帮助,加油!

Do you want to set this as a custom HTTP header and send it to the backend? 您是否要将其设置为自定义HTTP标头并将其发送到后端? If yes, then you can use a property mediator to set this as a transport scope property just before the send mediator inside inSequence of your API, as shown below. 如果是,则可以使用属性介体将此属性设置为传输作用域属性,就在API inSequence内部的发送介体之前,如下所示。 Have a look at the property Fixed-Authorization set just before the send mediator. 查看发送中介器之前的属性“固定授权”集。

<?xml version="1.0" encoding="UTF-8"?>
<api xmlns="http://ws.apache.org/ns/synapse"
     name="admin--Hello"
     context="/hello"
     version="1.0.0"
     version-type="url">
   <resource methods="POST GET OPTIONS DELETE PUT"
             url-mapping="/*"
             faultSequence="fault">
      <inSequence>
         <filter source="$ctx:AM_KEY_TYPE" regex="PRODUCTION">
            <then>
            <property name="Fixed-Authorization" value="yourAppToken" scope="transport"/>
               <send>
                  <endpoint name="admin--Hello_APIproductionEndpoint_0">
                     <http uri-template="http://echo.jsontest.com/key/value/one/two"/>
                  </endpoint>
               </send>
            </then>
            <else>
               <sequence key="_sandbox_key_error_"/>
            </else>
         </filter>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
   </resource>
   <handlers>
      <handler class="org.wso2.carbon.apimgt.gateway.handlers.security.APIAuthenticationHandler"/>
      <handler class="org.wso2.carbon.apimgt.gateway.handlers.throttling.APIThrottleHandler">
         <property name="id" value="A"/>
         <property name="policyKey" value="gov:/apimgt/applicationdata/tiers.xml"/>
      </handler>
      <handler class="org.wso2.carbon.apimgt.usage.publisher.APIMgtUsageHandler"/>
      <handler class="org.wso2.carbon.apimgt.usage.publisher.APIMgtGoogleAnalyticsTrackingHandler">
         <property name="configKey" value="gov:/apimgt/statistics/ga-config.xml"/>
      </handler>
      <handler class="org.wso2.carbon.apimgt.gateway.handlers.ext.APIManagerExtensionHandler"/>
   </handlers>
</api>

If you access the API, this property will be sent as a HTTP header to your backend endpoint. 如果您访问API,则此属性将作为HTTP标头发送到您的后端端点。 You can refer this post for more detailed explanation. 您可以参考这篇文章以获得更详细的解释。

If you just want to pass this application token to the backend (but not as HTTP header), then you can pass it to the backend using JWT. 如果您只想将此应用程序令牌传递给后端(但不作为HTTP标头),则可以使用JWT将其传递给后端。 Refer this document for more details. 有关更多详细信息,请参阅此文档

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

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