【问题标题】:WSO2 ESB Mediation Retrieve user attributes (claims) in inSequenceWSO2 ESB 中介在 inSequence 中检索用户属性(声明)
【发布时间】:2017-02-09 09:53:10
【问题描述】:

我已经在 API Publisher 中发布了 API。该 API 具有 POST 方法 confirm,它使用以下参数检索 JSON 数据:userUUID、appName、版本。在 API Publisher 中,此 API 仅接受两个参数:appName 和 version。

我不想从客户端发送 userUUID,但我想从 inSequence 中的 accessToken(它在用户声明中)检索 userUUID,并将其作为新参数添加到发送的 JSON,然后将其全部发送到后端。

有可能吗?也许我至少可以从 accessToken 检索用户电子邮件?

【问题讨论】:

    标签: json wso2 wso2esb wso2-am


    【解决方案1】:

    我看到了两种将用户信息传递到后端的方法。

    • 一个是 JWT 令牌。在 api-manager.xml 中,您可以使用声明检索器启用 JWT 令牌生成。 JWT 令牌将作为 HTTP 标头发送到后端服务

    • 您可以按顺序调用其中一项管理服务(请参阅https://docs.wso2.com/display/AM210/WSO2+Admin+Services)以获取分配的用户和应用程序

    请参阅https://localhost:9443/services/OAuth2TokenValidationService?wsdlvalidatebuildIntrospectionResponse 操作

    希望对你有帮助

    【讨论】:

    【解决方案2】:

    我找到了从https://localhost:9443/oauth2/userinfo?schema=openid 获取用户信息的解决方法

    首先,在文件[WSO2_AM]/repository/conf/api-manager.xml中更改OAuthConfigurations中的值RemoveOAuthHeadersFromOutMessage

    其次,来自https://localhost:9443/oauth2/userinfo?schema=openid 的用户声明应该在服务提供者的 WSO2 API Manager Carbon Server 中进行配置。

    算法:

    1. 将请求正文复制到属性body_of_zero_call
    2. 将请求目标 REST API 方法复制到属性 urlPostfixZero
    3. 将值 ?schema=openid 设置为请求目标 REST API 方法
    4. 拨打https://localhost:9443/oauth2/userinfo?schema=openid获取用户信息
    5. 检查响应码:如果为 200,则通过,否则返回码 500 并带有消息 { "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
    10. 使用属性user_uuid_first_call 中的值填充正文中的元素userUUID
    11. 使用更改的正文和目标 REST API 方法调用目标 URL
    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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-31
      • 2012-08-31
      • 1970-01-01
      • 1970-01-01
      • 2017-11-02
      相关资源
      最近更新 更多