是否可以在azure api管理中阻止用户使用api操作?
我编写了下面的代码来阻止用户从组开发中使用 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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
PS:未测试
PS: Not Tested
您可以使用“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