Microsoft图形API访问跨天蓝色

时间:2017-09-14 08:45:04

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

我使用azure活动目录来控制使用组成员身份访问我的Web应用程序。我有2个组(用户和管理员)。在我的应用程序中,我设置了Microsoft图形的应用程序权限,以读取用户配置文件并读取所有组。

然后我在我的应用中使用图形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中的主应用程序中,组信息存在,当我在天蓝色的qa&在dev环境中,这些组不存在于Claimsidentity对象中。为什么会这样?插槽是继承活动目录设置还是应单独设置?我对azure和安全模型都很陌生,所以任何帮助都会非常感激。

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

我正在使用OpenID

**更新2

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

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

我的天蓝色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活动目录作为已注册的应用程序,我有一个clientID和一个秘密,我已经给了它相同的azure权限活动目录和Microsoft图形作为我的主要应用程序。我已经包括了clientid&我的web.config转换中的秘密,所以基本上它的设置方式与我的主应用程序相同,STILL在Claimsidentity中没有组信息。这究竟是如何起作用的?

***另一次更新

授予的权限

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

Microsoft Graph   - 应用程序权限:读取所有用户的完整配置文件,读取所有组   - 委派权限:读取所有组,读取所有用户完整配置文件,登录并阅读用户配置文件

正如测试一样,我还授予了活动目录和Microsoft图表的所有权限,但没有任何区别。

现在这对我来说已经成为一个严重的问题了,我无法看到我能做的其他事情,它在我的主应用程序中运行得非常好,但不能在' slot' Azure有一个主要的缺陷/错误吗?或者我在这里做了一些根本性的错误?

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

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

您有权向该应用授予此问题的权限是什么?另请检查令牌中的scp声明,以确保已授予正确的权限。您可以从this link

解码访问令牌

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

Microsoft Graph permissions reference