【问题标题】:Getting Microsoft Graph Lifecycle Policies not working with Application permissions获取 Microsoft Graph 生命周期策略不适用于应用程序权限
【发布时间】:2018-05-07 02:27:05
【问题描述】:

我尝试创建一个 Azure 函数,将组生命周期策略应用于特定组,但由于应用程序权限而失败。

使用用户名和密码验证,这没有问题。

public static string GetAccessTokenForUser(string resourceUri, string aadDomain, string userName, string password)
    {
        var powershellClientId = "12128f48-ec9e-42f0-b203-ea49fb6af367";
        var azureADAuthority = $"https://login.microsoftonline.com/{aadDomain}/oauth/v2/authorize";
        var userCreds = new UserPasswordCredential(userName, password);
        var authContext = new AuthenticationContext(azureADAuthority, true);
        var authResult = AuthenticationContextIntegratedAuthExtensions.AcquireTokenAsync(authContext, resourceUri, powershellClientId, userCreds).GetAwaiter().GetResult();
        return authResult.AccessToken;
    }

使用 ClientId 和 ClientSecret 时总是返回 401 Unauthorized 错误。

public static string GetAccessTokenForClientId(string resourceUri, string aadDomain, string clientId, string clientSecret)
    {
        var azureADAuthority = $"https://login.microsoftonline.com/{aadDomain}/oauth/v2/authorize";
        var clientCreds = new ClientCredential(clientId, clientSecret);
        var authContext = new AuthenticationContext(azureADAuthority, true);
        var authResult = authContext.AcquireTokenAsync(resourceUri, clientCreds).GetAwaiter().GetResult();
        return authResult.AccessToken;
    }

然后我使用上一个函数中的访问令牌执行获取请求

GET https://graph.microsoft.com/beta/groupLifecyclePolicies

https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/api/grouplifecyclepolicy_list 的文档指出应用程序权限应该可以工作。访问令牌包含所需的范围,我检查了。

有人可以确认吗?

编辑 03/05/2018:自上周以来,这似乎在每个文档中再次起作用。我目前能够通过我的应用程序权限执行所有与生命周期相关的请求。

【问题讨论】:

  • 您能否添加诸如代码、配置文件或任何可以帮助社区解决您的问题的详细信息?
  • 我添加了代码示例。
  • 自上周以来,这似乎在每个文档中再次起作用。我目前能够通过我的应用程序权限执行所有与生命周期相关的请求。

标签: office365 microsoft-graph-api


【解决方案1】:

我有完全相同的问题 - 使用用于管理 O365 中的组的应用程序使用有限的用户权限并在应用程序权限下执行 O365 API 请求。

我测试了在应用程序权限下运行的应用程序(使用 Directory.ReadWrite.All),它在 12 月中旬左右运行良好。不幸的是,昨天测试时,它因缺少权限错误而失败。

我设法找到 this commit 到 Graph API 文档,其中显示了发生的情况。

Graph API 团队的任何人都可以告诉您是否计划在短期内返回此功能?这有很多有效的用途。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-16
    • 1970-01-01
    • 2023-01-02
    • 1970-01-01
    • 2020-04-24
    • 2021-06-29
    • 1970-01-01
    相关资源
    最近更新 更多