2017-02-09 140 views
0

我已經在API Publisher中發佈了API。該API具有POST方法confirm,該方法使用以下參數來檢索JSON數據:userUUID,appName,version。在API Publisher中,此API只接受兩個參數:appName和版本。WSO2 ESB調解檢索inSequence中的用戶屬性(聲明)

我不想從客戶端發送userUUID,但我想從inSequence中的accessToken(它在用戶聲明中)中檢索userUUID,並將其添加到發送的JSON作爲新參數,然後將其全部發送到後端。

可能嗎?也許我可以從accessToken中檢索至少用戶的電子郵件?

回答

0

我在文件中找到的解決方法與獲取用戶信息從https://localhost:9443/oauth2/userinfo?schema=openid

首先,變化值RemoveOAuthHeadersFromOutMessageOAuthConfigurations[WSO2_AM]/repository/conf/api-manager.xml

其次,用戶聲明,即從https://localhost:9443/oauth2/userinfo?schema=openid得到應WSO2 API管理碳服務器被配置在服務供應商。

算法:

  1. 複製請求主體的財產body_of_zero_call
  2. 拷貝請求目標REST API方法財產urlPostfixZero
  3. 設定值?schema=openid按要求目標REST API方法
  4. 呼叫https://localhost:9443/oauth2/userinfo?schema=openid獲得用戶info
  5. Check reponse code:if 200,then through,else return code 500 with message { "status": "Can't get user info"}
  6. 從反應體複製有趣的信息(在我的情況user_uuid)財產user_uuid_first_call
  7. 複製源請求主體從屬性body_of_zero_call到身體
  8. 複製源請求目標REST API方法從屬性urlPostfixZero以請求目標REST API方法
  9. 添加元素userUUID從財產user_uuid_first_call
  10. 呼叫目標與價值訴求的身體
  11. 填充元件userUUID身體URL與變化身體和目標REST API方法
  12. 迴應

中保

<?xml version="1.0" encoding="UTF-8"?> 
<sequence xmlns="http://ws.apache.org/ns/synapse" name="token_to_user_uuid" trace="disable"> 
    <!-- 1 --> 
    <enrich> 
     <source clone="true" type="body" /> 
     <target action="child" property="body_of_zero_call" type="property" /> 
    </enrich> 
    <!-- 2 --> 
    <property expression="$axis2:REST_URL_POSTFIX" name="urlPostfixZero" scope="default" type="STRING" /> 
    <!-- 3 --> 
    <property name="REST_URL_POSTFIX" scope="axis2" type="STRING" value="?schema=openid" /> 
    <!-- 4 --> 
    <call blocking="true"> 
     <endpoint> 
     <http method="get" trace="disable" uri-template="https://localhost:9443/oauth2/userinfo" /> 
     </endpoint> 
    </call> 
    <!-- 5 --> 
    <filter regex="200" source="get-property('axis2', 'HTTP_SC')"> 
     <then> 
     <!-- 6 --> 
     <property expression="$body//jsonObject//user_uuid" name="user_uuid_first_call" scope="default" type="STRING" /> 
     <!-- 7 --> 
     <enrich> 
      <source clone="true" property="body_of_zero_call" type="property" /> 
      <target type="body" /> 
     </enrich> 
     <!-- 8 --> 
     <property expression="get-property('urlPostfixZero')" name="REST_URL_POSTFIX" scope="axis2" type="STRING" /> 
     <!-- 9 --> 
     <enrich> 
      <source clone="true" type="inline"> 
       <userUUID xmlns="" /> 
      </source> 
      <target action="child" xpath="$body//jsonObject" /> 
     </enrich> 
     <!-- 10 --> 
     <enrich> 
      <source clone="true" property="user_uuid_first_call" type="property" /> 
      <target xpath="$body//jsonObject//userUUID" /> 
     </enrich> 
     <!-- 11 --> 
     <call blocking="true"> 
      <endpoint> 
       <http method="post" trace="disable" uri-template="https://localhost:9444/customAuth/services/regulations" /> 
      </endpoint> 
     </call> 
     <!-- 12 --> 
     <respond /> 
     </then> 
     <else> 
     <property name="HTTP_SC" scope="axis2" type="STRING" value="500" /> 
     <payloadFactory media-type="json"> 
      <format>{ "status": "Can't get user info"}</format> 
      <args /> 
     </payloadFactory> 
     <respond /> 
     </else> 
    </filter> 
</sequence> 
1

我看到兩種方式將用戶信息傳遞給後端。

  • 一個是JWT令牌。在api-manager.xml中,您可以使用索賠檢索器啓用JWT令牌生成。智威湯遜令牌將被髮送到後端服務的序列中的HTTP標頭

  • 可以調用的管理服務(見https://docs.wso2.com/display/AM210/WSO2+Admin+Services)對獲得分配的用戶和應用

看到https://localhost:9443/services/OAuth2TokenValidationService?wsdl一個和驗證buildIntrospectionResponse操作

我希望它幫

+0

非常有用的答案。你能告訴我,如何在序列中調用管理服務?也許我也可以按順序調用https:// localhost:9443/oauth2/userinfo?schema = openid? –

+0

已經解決。 –