【问题标题】:Microsoft graph API access issues across app service slots in azureAzure 中跨应用服务插槽的 Microsoft 图形 API 访问问题
【发布时间】:2017-09-14 08:45:04
【问题描述】:

我正在使用 azure Active Directory 来控制使用组成员身份对我的 Web 应用程序的访问。我有 2 个组(用户和管理员)。在我的应用程序中,我为 Microsoft graph 设置了应用程序权限,以读取用户配置文件并读取所有组。

然后我在我的应用程序中使用图形 api 来获取所有可用组的列表。这在我的本地开发环境中可以正常工作,当我在 azure 中部署到应用程序时,该过程也可以正常工作。当我在应用服务环境中的 2 个“插槽”中上传和测试时,就会出现问题。我有两个我正在使用,一个开发版本和一个 QA 版本。一旦我尝试从其中任何一个访问图形 api,我就会收到此错误

代码:Authorization_RequestDenied 消息:权限不足,无法完成操作。

我最初开始开发时就遇到了这个问题,但是设置和授予应用程序权限解决了这个问题。那么为什么我会在我的其他 2 个“应用程序”中得到这个?我需要这些来测试(我作为开发人员和我们的 QA 测试团队) 我是否需要采取任何其他步骤才能使我的开发和质量检查槽以相同的方式工作?

** 这是我访问图形 api 的方式,它在我的主应用程序中可以正常工作,但在插槽中却不行

GraphServiceClient graphClient = new GraphServiceClient(new AzureAuthenticationProvider());
Group group = await graphClient.Groups[admin].Request().GetAsync();

**更新

问题在于我的插槽中运行的应用程序。用户登录后,我的 Dev 和 QA 插槽在 ClaimsIdentity 对象中都没有任何组信息。我通过在 Claimsidentity 对象中记录信息来检查这一点,当我在本地和 Azure 的主应用程序中运行它时,组信息存在,当我在 azure qa & dev 环境中运行它时,组不存在于 Claimsidentity 对象中。为什么会这样?插槽是继承活动目录设置还是应该单独设置?我对 azure 和安全模型非常陌生,因此我们将不胜感激。

我在 azure 和我的 web.config 中设置了重定向 url,我为每个环境使用了不同的转换,并为每个环境使用了适当的重定向。

我正在使用 OpenID

**更新 2

当我创建插槽时,我将它们(复制)基于我的主应用程序。每个插槽是否应该在其 web.config 文件中有自己的 ClientID 和机密?我还需要将每个插槽注册为活动目录中的应用程序吗?目前只注册了我的主应用程序

这是我每个应用程序的声明,您可以看到 qa 应用程序没有组

我在 azure 中的 QA 槽

Claim type - ver
Claim type - http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name
Claim type - http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn
Claim type - http://schemas.microsoft.com/identity/claims/tenantid
Claim type - http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier
Claim type - onprem_sid
Claim type - nonce
Claim type - http://schemas.microsoft.com/identity/claims/objectidentifier
Claim type - name
Claim type - http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname
Claim type - ipaddr
Claim type - http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname
Claim type - http://schemas.microsoft.com/claims/authnmethodsreferences
Claim type - c_hash
Claim type - aio
Claim type - exp
Claim type - nbf
Claim type - iss
Claim type - iat
Claim type - aud

认证类型;饼干

我在 Azure 中的主要应用程序

Claim type - ver
Claim type - http://schemas.microsoft.com/identity/claims/tenantid
Claim type - http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name
Claim type - http://schemas.microsoft.com/identity/claims/objectidentifier
Claim type - http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier
Claim type - nonce
Claim type - name
Claim type - ipaddr
Claim type - http://schemas.microsoft.com/identity/claims/identityprovider
Claim type - groups
Claim type - groups
Claim type - http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname
Claim type - http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname
Claim type - http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress
Claim type - c_hash
Claim type - http://schemas.microsoft.com/claims/authnmethodsreferences
Claim type - exp
Claim type - aio
Claim type - nbf
Claim type - iss
Claim type - iat
Claim type - aud

认证类型;饼干

** 好的,我已经尝试将 QA 应用程序作为注册应用程序添加到 azure Active Directory,我有一个 clientID 和一个秘密,我已经为 azure Active Directory 和 Microsoft graph 赋予了相同的权限我的主要应用程序。我已经在我的 web.config 转换中包含了 clientid 和 secret,所以基本上它的设置方式与我的主应用程序相同,并且在 Claimsidentity 中仍然没有组信息。这到底是怎么工作的?

***另一个更新

已授予权限

windows azure 活动目录 - 委托权限:读取所有组,读取所有用户完整配置文件

微软图形 - 应用程序权限:读取所有用户的完整配置文件,读取所有组 - 委派权限:读取所有组、读取所有用户的完整个人资料、登录并读取用户个人资料

作为测试,我还授予了活动目录和 Microsoft graph 的所有权限,这没有任何区别。

现在这对我来说已成为一个严重的问题,我看不出还有什么可以做的,它在我的主应用程序中运行良好,但不是在“插槽”中 Azure 是否存在重大缺陷/错误? ,还是我在这里做一些根本错误的事情?

谁能帮帮我?

【问题讨论】:

  • 有人吗?这是一个大问题,我无法在 azure 中测试我的开发和 qa 版本的任何安全功能:-(

标签: azure c#-4.0 azure-active-directory


【解决方案1】:

要通过 Microsoft Graph 读取组,需要 Group.Read.AllGroup.ReadWrite.AllDirectory.Read.AllDirectory.ReadWrite.All

您对存在此问题的应用授予了哪些权限?另请检查令牌中的scp 声明,以确保已授予正确的权限。您可以从this link 解码访问令牌

有关 Microsoft Graph REST 权限的更多详细信息,请参阅以下链接:

Microsoft Graph permissions reference

【讨论】:

  • 'slots' 是否继承主应用程序的活动目录设置?好像不是这样,我还需要做些什么吗?
  • 您是如何与 Azure Active Directory 交互的?使用 OpenID OWIN 组件还是 Easy Auth?如果您使用的是 OpenID OWIN 组件,这取决于您如何配置它,除了重定向 URL 之外,大部分代码都不需要修改。如果您使用 Easy Auth,您应该为部署的插槽重新配置它。
  • 我正在使用 OpenID,刚刚为我的问题添加了更新
  • @proteus 您是否在部署新插槽时复制了 web.config?如果没有,您是否为不同的插槽配置了不同的应用设置?
  • 我还检查了我在 azure 中的 qa 和 dev 的重定向 URL,它们都符合我的预期
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-12-07
  • 2019-11-28
  • 2022-09-28
  • 1970-01-01
  • 1970-01-01
  • 2015-07-31
  • 2021-02-17
相关资源
最近更新 更多