【问题标题】:Custom response body for validate-jwt in Azure APIMAzure APIM 中 validate-jwt 的自定义响应正文
【发布时间】:2020-04-02 09:36:45
【问题描述】:

我正在验证来自 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 Manager 中可以吗?

【问题讨论】:

    标签: azure azure-devops azure-api-management api-management


    【解决方案1】:

    我已经设法通过以下转换策略解决了这个问题。

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

    【讨论】:

    • 这按预期工作。但是,我想设置标题WWW-Authenticate : Bearer realm="my_sample_realm"。此处的标题键在响应中变为小写,而不是将大小写保留为WWW-Authenticate。有什么办法可以保全案子吗?
    • 您能添加您的入站配置吗?
    • login.microsoftonline.com/my_tenant_org_id/v2.0/.well-known/…" /> my_audiencemy_issuerclients.manage
    • 这是我在 &lt;inbound&gt; 标签内的 JWT 验证。
    • 根据您的建议提出了一个新问题stackoverflow.com/questions/69288455/…@Justin Mathew
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-12-06
    • 1970-01-01
    • 1970-01-01
    • 2020-10-29
    • 2020-10-17
    • 2021-09-16
    • 2020-03-15
    相关资源
    最近更新 更多