英文:
How to send end user name of api invoker to the backend in wso2 apim
问题
我正在测试WSO2 APIM 4.0.0发布者门户的自定义调解功能,以将API调用者的端用户名称发送到后端。我遵循了此参考链接 并创建了以下自定义序列:
<sequence name="test" xmlns="http://ws.apache.org/ns/synapse">
<header name="user" expression="substring-before(get-property('api.ut.userId'), '@')" scope="transport"/>
</sequence>
将此序列添加为我的测试API的自定义请求调解。该API本身只是一个简单的REST API,返回静态字符串,另外它将所有标头打印到控制台:
@RestController
@RequestMapping("greet")
public class GreetApi {
@GetMapping
public String greet(@RequestHeader Map<String, String> headers) {
System.out.println(headers);
return "Greetings";
}
}
但它没有将端用户名称作为自定义标头打印到控制台:
{activityid=3221a82e-0679-4f6e-9a36-bd9abdefb6a4, accept=*/*, host=localhost:8080, user=, connection=Keep-Alive, user-agent=Synapse-PT-HttpComponents-NIO}
非常感谢任何关于解决此问题的指导。
英文:
I am testing the custom mediation feature of wso2 apim 4.0.0 publisher portal to send end user name of api invoker to the backend. I followed this reference and created the following custom sequence:
<sequence name="test" xmlns="http://ws.apache.org/ns/synapse">
<header name="user" expression="substring-before(get-property('api.ut.userId'), '@')" scope="transport"/>
</sequence>
Added this sequence as a custom request mediation of my test api. The api itself nothing but simple rest api that returns static string, besides it prints all headers to console:
@RestController
@RequestMapping("greet")
public class GreetApi {
@GetMapping
public String greet(@RequestHeader Map<String,String> headers) {
System.out.println(headers);
return "Greetings";
}
}
But it's not printing the end user name as a custom header in console:
{activityid=3221a82e-0679-4f6e-9a36-bd9abdefb6a4, accept=*/*, host=localhost:8080, user=, connection=Keep-Alive, user-agent=Synapse-PT-HttpComponents-NIO}
Any navigation to address this issue is highly appreciated
答案1
得分: 0
另一种方法是将来自客户端的JWT令牌传递到后端并解码它,然后获取用户名。为此,请将以下内容添加到deployment.toml
文件中:
[apim.oauth_config]
enable_outbound_auth_header = true
英文:
Another approach is to pass the JWT token coming from the client to the back and decode it and get the username. For this add the following to the deployment.toml
[apim.oauth_config]
enable_outbound_auth_header = true
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论