2014-01-16 36 views
1

這是服務標註政策:如何基本身份驗證添加到服務標註政策

<ServiceCallout name="GeoCodeClient"> 
    <Request clearPayload="false" variable="GeocodingRequest" /> 
    <Response>GeocodingResponse</Response> 
    <Timeout>30000</Timeout> 
    <HTTPTargetConnection> 
     <URL>http://maps.googleapis.com/maps/api/geocode/json</URL> 
    </HTTPTargetConnection> 
</ServiceCallout> 

讓我們說我要訪問的資源,爲用戶名/密碼保護。我如何將此基本授權添加到此策略中以使我可以這樣做?

+0

敏感數據看一看這個答案http://stackoverflow.com/a/21057641/808096 –

回答

2

在我們的項目中,KeyValueMaps用於存儲組織級別的基本認證信息。使用KeyValueMap policy檢索授權信息,並將其添加爲請求消息的基本身份驗證標頭。

看看這種方法是否適合你。

+0

我喜歡這種方法 – user1801279

+3

將是理想這裏也提供了一個基本的例子,因爲doc的URL將來會發生變化。 – brandonscript

+0

不知道我明白,雖然我措辭作爲解決問題的方式。這是問題作者提出的問題的解決方案之一。請讓我知道你的想法。 – Srikanth

2

要增加基本認證頭爲您服務標註,您可以按以下使用「AssignMessage」政策設置「授權」頭中的「GeocodingRequest」:

<AssignMessage enabled="true" continueOnError="true" async="false" name="AssignAuthorizationHeaderPolicy"> 
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> 
    <AssignTo createNew="true" transport="http" type="request">GeocodingRequest</AssignTo> 
    <Add> 
     <Headers> 
      <Header name="Authorization">Basic YourAuthenticationHeader</Header> 
     </Headers> 
    </Add> 
</AssignMessage> 

一旦你創建了這個政策,你需要將它連接在請求流serviceCallout之前在名爲proxy.xml如流:

  <Step> 
       <FaultRules/> 
       <Name>AssignAuthorizationHeaderPolicy</Name> 
      </Step> 
      <Step> 
       <FaultRules/> 
       <Name>GeoCodeClient</Name> 
      </Step> 
0

到什麼已經說過添加到,如果你需要base64編碼(你可能會,如果你」重新使用基本授權),您需要執行sc ript標註。例如,你可以使用下面的Python:

import base64 

if (client_secret is not None): 
data = client_id + ":" + client_secret 
header_value = base64.b64encode(data) 
header_value = "Basic " + header_value 
flow.setVariable("request.header.Authorization", header_value) 

JS會有點麻煩,因爲你需要包括相應的庫,但我敢肯定,因此具有足夠的更多的例子來遵循這一點。

0

使用關鍵值映射到存儲在一個安全的方式

Step 1)Use below API to Create/Update the key Value maphttps://api.enterprise.apigee.com/v1/o/{orgname}/environments/{env}/keyvaluemaps Body:-{ 
    "entry" : [ { 
    "name" : "basic_auth_system1", 
    "value" : "Basic XXXXXXXXXXX" 
    } ], 
    "name" : "system1_credentials" 
} 
Step 2) Policy used to lookup The key Value map 

<KeyValueMapOperations enabled="true" continueOnError="false" async="false" name="keymap_get_credentials" mapIdentifier="system1_credentials"> 
    <DisplayName>keymap_get_credentials</DisplayName> 
    <FaultRules/> 
    <Properties/> 
    <ExpiryTimeInSecs>-1</ExpiryTimeInSecs> 
    <Get assignTo="basic_auth_system1"> 
     <Key> 
      <Parameter>basic_auth_system1</Parameter> 
     </Key> 
    </Get> 
    <Scope>environment</Scope> 
</KeyValueMapOperations>