【发布时间】:2020-09-24 18:02:46
【问题描述】:
我的项目使用 api 管理服务作为 azure APIM。我正在尝试使用 APIM 产品政策验证声明。如果声明无效,则返回错误,否则允许访问端点。以下是我的政策
<policies> <inbound> <validate-jwt header-name="Authorization" failed-validation-httpcode="401" failed-validation-error-message="Unauthorized. Access token is missing or invalid.">
------------
------------
</validate-jwt>
<choose>
<when condition="@(context.Request.Method != "POST" && ((Jwt)context.Request.Headers["Authorization"].Claims["role"]!= "Owner") && (string)context.Api.Path =="/api/user">
<return-response>
<set-status code="403" reason="Forbidden" />
</return-response>
</when> </choose>
<base />
</inbound> <backend> <base /> </backend> <outbound> <base /> </outbound> <on-error> <base /> </policies>
但是即使角色不是所有者用户也可以访问 /api/user 路径 如何正确验证?
JWT calims are
"userrole": "[Owner,Admin]",
"email": "test@gmail.com"
【问题讨论】:
-
如果对你有帮助,欢迎采纳。
标签: azure azure-api-management