azure - Azure APIM 中 validate-jwt 的自定义响应正文
问题描述
我正在验证来自 Azure API 管理器的 JWT 令牌。我正在寻找验证失败时更改响应正文的选项。根据文档https://docs.microsoft.com/en-us/azure/api-management/api-management-access-restriction-policies。
<validate-jwt
header-name="name of http header containing the token (use query-parameter-name attribute if the token is passed in the URL)"
failed-validation-httpcode="401"
failed-validation-error-message="Invalid Token"
token-value="expression returning JWT token as a string"
require-expiration-time="true|false"
require-scheme="scheme"
require-signed-tokens="true|false"
clock-skew="allowed clock skew in seconds"
output-token-variable-name="name of a variable to receive a JWT object representing successfully validated token">
如果我设置
failed-validation-httpcode="401" and failed-validation-error-message="Invalid Token"
验证失败时的响应是
{
"statusCode": 401,
"message": "Invalid Token"
}
现在我需要将正文中的“statusCode”更改为“status”响应
{
"status": 401,
"message": "Invalid Token"
}
在 Azure API 管理器中可以吗?
解决方案
我已经设法通过以下转换策略解决了这个问题。
<on-error>
<choose>
<when condition="@(context.Response.StatusCode == 401)">
<find-and-replace from="statusCode" to="status" />
</when>
</choose>
</on-error>
推荐阅读
- angular - HttpClient 不发出 http 网络请求
- guidewire - 如何在策略中心创建自定义事件
- django - 如何使用 QuerySet 输出 CSV 文件
- spring-boot - 我正在尝试将 IBMMQ 与我的 Spring Boot 应用程序连接,但连接应该通过 spid(pki)。有人知道该怎么做吗?
- python - 自动编码器重建图像(输出)不清楚,因为我想要
- xslt - XSLT。将数字转换为印度格式
- c++ - 当类的成员存储为没有此类方法的父类的对象时,如何访问该类的成员?
- sonarqube - 如何在 sonarqube 中获取 scm 帐户搜索的代码行
- javascript - Bootstrap 手风琴在另一个打开时隐藏
- java - 调用 onClick 时出现“OutOfMemoryError”(崩溃报告)