2016-12-26 55 views
0

我對WSO2 esb很陌生,我仍在評估它。我試圖使用OAuth保護的Web服務。在我的順序我創建了一箇中介的OAuth這樣的片段:當我嘗試使用cURL命令行它的工作原理沒有問題如何使用OAuth保護的Web服務?

MessageID: urn:uuid:ba554008-3b7c-4a96-875b-d04cc8fa179b, Direction: request, MESSAGE = Executing default 'fault' sequence, ERROR_CODE = 0, ERROR_MESSAGE = Not a valid OAuth Request, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body/></soapenv:Envelope> {org.apache.synapse.mediators.builtin.LogMediator} 

curl -X GET --header "Accept: application/json" --header "Authorization: Bearer 3ef47ff9ae9f0600aa279a0f77ddfdf" "https://myserver.com/ws-test" -k 

<?xml version="1.0" encoding="UTF-8"?> 
<sequence name="test-consume-oauth_v1" xmlns="http://ws.apache.org/ns/synapse"> 
    <in> 
     <property expression="json-eval($.)" name="test-consume-oauth_v1 Body_received" scope="default" type="STRING" /> 

     <oauthService xmlns="http://ws.apache.org/ns/synapse" password="xxx" 
      remoteServiceUrl="https://myserver.com/token" username="xxx"/> 
     <call> 
      <endpoint key="test_OAUTH_v1"/> 
     </call> 

     <script language="js"><![CDATA[var srvResponse = mc.getPayloadJSON(); 
      mc.setProperty('srvResponse', srvResponse);]]></script> 
     <log> 
      <property expression="json-eval($.)" name="test-consume-oauth_v1 response "/> 
     </log> 
     <script language="js"><![CDATA[var log = mc.getServiceLog(); 

      mc.setPayloadJSON(mc.getProperty('srvResponse')); 

     ]]></script> 

     <respond /> 
    </in> 
    <out> 
     <send /> 
     <drop /> 
    </out> 
</sequence> 

但它仍然顯示此錯誤

總結我如何在cURL命令行中執行Wso2 esb中的相同操作?

問候

+0

啓用wirelogs,並檢查該請求是否從ESB走的是正確的 –

+0

你可以發佈作出ESB的要求(身體,HTTP頭)問題?根據錯誤它說,不是一個有效的oauth請求,請確保您發送oauth標記頭'授權:承載xxxxx' – Jenananthan

回答

0

我用調解員頭部像

<header name="Authorization" scope="transport" value="3ef47ff9ae9f0600aa27efd6565" /> 

<call> 
     <endpoint key="test_OAUTH_v1"/> 
</call> 
.... 

那工作不錯。但問題是令牌生存期很短,所以我必須存儲當前令牌,如果它不是有效的,我必須要求一個新的有效令牌。我認爲wso2esb可以完成這個過程,但我不知道如何處理。

你有什麼主張嗎?

0

oauth調解器用於使用oauth來保護不安全的後端。在你的情況下,你的後端已經被oauth保護了,你需要通過提供oauth標記來通過esb來調用它。您需要使用密碼授權類型動態生成oauth標記並將其用於調用後端。因此,您可以按照序列中的以下步驟實現此目的:

  1. 使用有效負載工廠中介爲標記端點創建負載。 有效載荷令牌端點 - 「grant_type =密碼&用戶名=管理員&密碼= XXX」

<property name="grant_type" value="password" scope="default" type="STRING"/> 
 
    <property name="username" value="admin" scope="default" type="STRING"/>/> 
 
    <property name="password" value="xxxx" scope="default" type="STRING"/>/> 
 
       
 
    <payloadFactory media-type="xml"> 
 
        <format> 
 
         <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
 
          <soapenv:Body> 
 
           <root> 
 
            <grant_type>$1</grant_type> 
 
            <username>$2</username> 
 
            <country>$3</country>         
 
           </root> 
 
          </soapenv:Body> 
 
         </soapenv:Envelope> 
 
        </format> 
 
        <args> 
 
         <arg evaluator="xml" expression="$ctx:grant_type"/> 
 
         <arg evaluator="xml" expression="$ctx:username"/> 
 
         <arg evaluator="xml" expression="$ctx:password"/> 
 
        </args> 
 
    </payloadFactory>    
 
    <property name="messageType" value="application/x-www-form-urlencoded" scope="axis2" type="STRING"/> 
 
    <property name="DISABLE_CHUNKING" value="true" scope="axis2" type="STRING"/>

使用
  • 呼叫令牌端點呼叫調解員並從響應中提取令牌並添加到授權標頭
  • a。

    <call> 
     
         <endpoint key="TokenEndpoint"/> 
     
    </call>

    灣 從響應中提取令牌

    c。 設置令牌授權頭使用頭中介

    3.Call實際後端

    +0

    坦克Jenanthan我試過你的代碼,但它不起作用 –