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

Chrome Outlook扩展OAuth2报错:无效范围,无法获取身份令牌

问题分析与解决方案

错误提示invalid scope: https://graph.microsoft.com/User.Read的核心原因是Chrome扩展OAuth2配置中,Microsoft Graph的scope格式错误——不需要带完整的API域名前缀,直接使用权限名称即可。

具体修复步骤

1. 修正manifest.json中的OAuth2 Scope配置

将oauth2.scopes里的"https://graph.microsoft.com/User.Read"替换为"User.Read",正确的scope列表如下:

"oauth2": {
  "client_id":"your-client-id",
  "scopes": [
    "openid", 
    "email", 
    "profile", 
    "User.Read"
  ]
}

说明:Azure AD会自动为Microsoft Graph权限拼接正确的域名前缀,带完整URL的写法会被识别为无效scope。

2. 验证Azure应用权限配置

确保你的Azure AD应用已添加委托权限(Delegated permissions):

  • openid、profile、email(属于OpenID Connect权限组)
  • User.Read(属于Microsoft Graph权限组)
    并已完成权限授予(管理员同意或用户同意,取决于应用类型)。

3. 优化Graph API请求(可选)

如果需要明确获取邮箱字段,可以修改请求URL,只返回需要的信息,减少数据传输:

fetch("https://graph.microsoft.com/v1.0/me?$select=mail,userPrincipalName", {
  headers: {
    Authorization: "Bearer " + token,
  },
})

返回的mail字段即为用户的邮箱地址,userPrincipalName通常也是邮箱格式(适用于组织账号)。

修正后的完整manifest.json示例

{
    "manifest_version": 3,
    "name": "Plugin for Outlook",
    "description": "Base Level Extension",
    "version": "1.0",
    "action": {
      "default_popup": "popup/popup.html",
      "default_icon": "images/logo.png"
    },
    "permissions": [
      "contextMenus",
      "activeTab",
      "scripting",
      "storage",
      "identity"
    ],
    "host_permissions": [
      "https://graph.microsoft.com/*",
      "https://ccqrs034g7.execute-api.us-east-1.amazonaws.com/*"
    ],
    "background": {
        "service_worker": "background.js"
    },
    "oauth2": {
      "client_id":"your-client-id",
      "scopes": [
        "openid", "email", "profile", "User.Read"
      ]
    },
    "content_scripts":[
        {
          "matches": ["<all_urls>"],
            "js":["contentScript.js"] 
        }
    ]
}

内容的提问来源于stack exchange,提问作者Fuzail Mirza

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 00:22:11