azure - Azure APIM 中 validate-jwt 的自定义响应正文

标签 azure azure-devops azure-api-management ibm-api-management

我正在验证来自 Azure API Manager 的 JWT token 。我正在寻找在验证失败时更改响应正文的选项。根据文档https://learn.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 Manager 中可以吗?

最佳答案

我已设法通过以下转换策略解决此问题。

 <on-error>
     <choose>
         <when condition="@(context.Response.StatusCode == 401)">
            <find-and-replace from="statusCode" to="status" />
         </when>
    </choose> 
</on-error>

关于azure - Azure APIM 中 validate-jwt 的自定义响应正文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60988489/

相关文章:

azure - 云提供商如何实际实现 FaaS/Serverless 架构

asp.net - SQL CE azure 连接

azure - ARM 模板 - 不允许主模板中存在多个链接模板

tfs - 通过 TFS Rest API 创建测试套件时出现 "Response status code does not indicate success: 500 (Internal Server Error)"

Azure 中的 API 安全最佳实践

Azure Api 管理日志用户访问的 api

azure - 自动从 Azure Function App 更新到 API 管理

azure - Graph API 正在从 AzureAD 中的企业应用程序中删除证书

git - 从 Git 本地部署到 Azure System.IO.IOException : There is not enough space on the disk

azure - 如何使用 New-AzADSpCredential 添加证书凭据