【问题标题】:Microsoft365R get_business_outlook: "Forbidden (HTTP 403). Failed to complete operation. Message: Insufficient privileges to complete the operation."Microsoft365R get_business_outlook:\“禁止访问(HTTP 403)。无法完成操作。消息:权限不足,无法完成操作。\”
【发布时间】:2022-12-14 10:24:42
【问题描述】:

我正在尝试使用 Microsoft365R 的 get_business_outlook 功能通过我的 business outlook 帐户访问我具有读/写权限的共享邮箱。

library(Microsoft365R)

tenant_id <- "example_tenant_id"
email <- "example@example.co.uk"

outl <- get_business_outlook(tenant_id, shared_mbox_email = email)

我第一次尝试此操作时,收到消息:

使用 authorization_code 流程
为租户“example_tenant_id”创建 Microsoft Graph 登录
使用 authorization_code 流程
正在等待浏览器中的身份验证...
按 Esc/Ctrl + C 中止
身份验证完成。
process_response(res, match.arg(http_status_handler), simplify) 错误:
禁止 (HTTP 403)。无法完成操作。信息:
权限不足,无法完成操作。

在随后的运行中,我得到:

process_response(res, match.arg(http_status_handler), simplify) 错误:
禁止 (HTTP 403)。无法完成操作。信息:
权限不足,无法完成操作。

我已经看到 this answer 提出了类似的问题,但是使用 app 参数没有帮助:

app_id <- "example_app_id"

outl <- get_business_outlook(tenant_id, shared_mbox_email = email, app = app_id)

正在加载租户“example_tenant_id”的 Microsoft Graph 登录
process_response(res, match.arg(http_status_handler), simplify) 错误:
禁止 (HTTP 403)。无法完成操作。信息:
权限不足,无法完成操作。

我尝试创建一个令牌,有和没有 resource 参数:

library(AzureAuth)
# Without resource
tok <- get_azure_token("", tenant=tenant_id, app=app_id)

使用 authorization_code 流程
加载缓存令牌

outl <- get_business_outlook(tenant_id, shared_mbox_email = email, app = app_id, token = tok)

错误:找不到图形主机 URL

# With resource
resource <- "https://graph.microsoft.com/Mail.ReadWrite.Shared"
# Get azure token for app
tok <- get_azure_token(resource, tenant=tenant_id, app=app_id)

这将打开一个浏览器窗口,提示我使用 SSO 登录并显示“未找到”文本。

就像链接问题的海报一样,我是 Graph API 的新手,并且使用了很多 Azure 术语,所以我可能遗漏了一些明显的东西。任何帮助表示赞赏。

【问题讨论】:

    标签: r microsoft-graph-api azure-authentication microsoft365 microsoft365r


    【解决方案1】:

    错误403 Forbidden如果您不需要,通常会发生权限或者角色执行操作。

    我试图通过邮递员在我的环境中重现相同的内容并得到与下面相同的错误

    GET https://graph.microsoft.com/v1.0/users/<usermail.com>/messages
    

    解决错误,确保在下面添加委派许可并授予管理员同意:

    现在我再次使用生成访问令牌授权码具有以下参数的流:

    POST https://login.microsoftonline.com/<tenantID>/oauth2/v2.0/token
    client_id:<appID>
    grant_type:authorization_code
    scope:https://graph.microsoft.com/Mail.ReadWrite.Shared
    code:code
    redirect_uri:https://jwt.ms
    client_secret:secret
    

    当我使用上面的令牌访问共享邮箱时,我得到了回复成功如下:

    在您的情况下,请确保授予管理员同意获取 Azure AD 应用程序中的 API 权限。

    如果你想生成v1 代币,然后在如下代码中删除资源末尾的范围名称:

    library(AzureAuth)
    token <- get_azure_token("https://graph.microsoft.com", tenant="yourtenant", app="yourappid")
    

    包括版本如果要生成参数v2 代币如下所示:

    library(AzureAuth)
    token <- get_azure_token("https://graph.microsoft.com/Mail.ReadWrite.Shared", tenant="yourtenant", app="yourappid", version=2)
    

    如果仍然存在错误,请获取行政人员角色并通过使用管理员凭据签名来尝试相同的操作。

    参考:Common authentication scenarios (r-project.org)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-30
      • 1970-01-01
      • 1970-01-01
      • 2017-11-03
      • 2018-06-13
      • 2018-01-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多