繁体   English   中英

WSO2 ESB中介按顺序检索用户属性(声明)

[英]WSO2 ESB Mediation Retrieve user attributes (claims) in inSequence

我已经在API Publisher中发布了API。 该API有POST方法confirm ,它与这样的参数检索JSON数据:userUUID,APPNAME,版本。 在API Publisher中,此API仅采用两个参数:appName和version。

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

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

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

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

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

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

希望对您有所帮助

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

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

其次,应该在服务提供商的WSO2 API Manager Carbon Server中配置从https://localhost:9443/oauth2/userinfo?schema=openid获得的用户声明。

算法:

  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. 从属性urlPostfixZero复制源请求目标REST API方法以请求目标REST API方法
  9. 将元素userUUID添加到请求正文
  10. 填充元件userUUID身体与属性值user_uuid_first_call
  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>

暂无
暂无

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

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