是否可以在azure api管理中阻止用户使用api操作?

发布于 2025-01-15 11:23:17 字数 482 浏览 2 评论 0 原文

我编写了下面的代码来阻止用户从组开发中使用 api 操作。我想知道是否有一种方法可以阻止组中的用户访问特定方法(例如 put、delete)并且只允许组中的用户使用 get 方法?

<choose>
    <when condition="@(context.User.Groups.Any(g => g.Name == "dev"))">
        <return-response>
            <set-status code="403" reason="Unauthorized" />
            <set-body>Users in group dev do not have access to this method.</set-body>
        </return-response>
    </when>
</choose>

I wrote below code for blocking user from group dev, from using an api operation. I would like to know if there is a method for blocking users in a group from accessing a particular method like put, delete and only allow user from a group to use get method?

<choose>
    <when condition="@(context.User.Groups.Any(g => g.Name == "dev"))">
        <return-response>
            <set-status code="403" reason="Unauthorized" />
            <set-body>Users in group dev do not have access to this method.</set-body>
        </return-response>
    </when>
</choose>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧人九事 2025-01-22 11:23:17
 <set-variable name="isAccessible" value="@(context.User.Groups.Any(g => g.Name == "dev") && context.Request.Method==PUT)" />

 <choose>
       <when condition="@(context.Variables.GetValueOrDefault<bool>("isAccessible"))">
            <return-response>
                 <set-status code="403" reason="Unauthorized" />
                <set-body>Users in group dev do not have access to this method.</set-body>
            </return-response>
         </when>
     </choose>

PS:未测试

 <set-variable name="isAccessible" value="@(context.User.Groups.Any(g => g.Name == "dev") && context.Request.Method==PUT)" />

 <choose>
       <when condition="@(context.Variables.GetValueOrDefault<bool>("isAccessible"))">
            <return-response>
                 <set-status code="403" reason="Unauthorized" />
                <set-body>Users in group dev do not have access to this method.</set-body>
            </return-response>
         </when>
     </choose>

PS: Not Tested

临走之时 2025-01-22 11:23:17

您可以使用“validate-jwt”策略并根据调用的方法允许/限制访问。用户在调用 API 时将出示 JWT 令牌,您可以使用操作级别策略或 API 级别策略(基于方法检查)并验证 JWT 令牌声明。

您可以在此处参考 Microsoft 文档以了解策略的使用: https://learn.microsoft.com/en-us/azure/api-management/api-management-access-restriction-policies#ValidateJWT

You can use 'validate-jwt' policy and Allow/restrict the access based on method called. Users will present the JWT token while calling the API, you can use operation level policy or API level policy(based on method check) and verify the JWT token claim.

You can refer microsoft documentation here for use of policy: https://learn.microsoft.com/en-us/azure/api-management/api-management-access-restriction-policies#ValidateJWT

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文