You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SPFx WebPart向Azure服务总线队列发送消息时遇「需要Send权限声明」授权错误的求助

SPFx WebPart向Azure服务总线队列发送消息时遇「需要Send权限声明」授权错误的求助

大家好,我最近在尝试从SPFx WebPart向Azure Service Bus队列发送测试消息,但每次都碰到授权错误:

Unauthorized access. 'Send' claim(s) are required to perform this operation. Resource: 'sb://.servicebus.windows.net/'.

下面是我已经执行的步骤,麻烦帮忙看看哪里出问题了:

  • 创建了一个示例SPFx WebPart
  • 在package-solution.json的webApiPermissionRequests中添加了以下权限配置:
    {
      "resource": "Microsoft.ServiceBus",
      "scope": "user_impersonation"
    }
    
  • 部署WebPart后,在管理员中心批准了权限范围,此时Azure AD中创建了带有对应API权限的服务主体
  • 为了适配MSAL 2.0的PKCE流程,将AD应用的重定向URI迁移到SPA类型,并设置「允许公共客户端流」为"Yes"
  • 获取AD应用的客户端ID和租户ID,在SPFx解决方案中使用JavaScript SDK连接Service Bus队列
  • 使用@azure/identity的InteractiveBrowserCredential和@azure/service-bus的ServiceBusClient来发送消息,代码片段如下:
    try{
      const credential = new InteractiveBrowserCredential({
        tenantId: "<tenant-id>",
        clientId: "<SharePoint Online Client Extensibility Web Application Principal client-id>"
      });
      const fullyQualifiedNamespace = "<servicebus-namespace>.servicebus.windows.net";
      const serviceBusClient = new ServiceBusClient(fullyQualifiedNamespace, credential);
      const sender = serviceBusClient.createSender("queue-name");
      await sender.sendMessages({body: "test"});
      console.log("message sent");
    }
    catch(error){
      console.log(error);
    }
    
  • 已经在IAM中给该服务主体分配了「所有者」和「Azure Service Bus数据所有者」权限,并且在队列和服务总线命名空间级别都设置了

但不管怎么调试,代码都会抛出开头提到的那个授权错误,实在找不到原因了,有没有大佬能指点一下?感谢!

备注:内容来源于stack exchange,提问作者Soumit

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.23 13:07:36