簡體   English   中英

Azure APIM 中 validate-jwt 的自定義響應正文

[英]Custom response body for validate-jwt in Azure APIM

我正在驗證來自 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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM