Python MSAL-当已经给予同意时,需要管理员同意

时间:2020-11-12 20:54:46

标签: azure-active-directory microsoft-graph-api msal

我正在尝试使用Microsoft的MSAL库请求Directory.Read.All范围,并使用acquire_token_by_authorization_code函数检索有效的访问/刷新令牌对。

我请组织的管理员通过/adminconsent端点同意上述应用程序权限(并确认已授予权限-请参见下面的屏幕快照)。但是,当尝试使用Directory.Read.All范围检索访问令牌时,出现以下错误:

{'error': 'invalid_grant', 'error_description': "AADSTS65001: The user or administrator has not consented to use the application with ID 'XXX' named 'XXX'. Send an interactive authorization request for this user and resource [...]'suberror': 'consent_required'}

不确定是否会发生这种情况-因为已明确授予了许可。我曾尝试通过删除所有MSAL帐户来重置令牌缓存,但是我怀疑这是问题的根源,因为失败的实际步骤是将授权代码转换为访问令牌。

感谢您的帮助!

Microsoft AD page for permissions

1 个答案:

答案 0 :(得分:0)

我可以重现您的错误:

enter image description here

如果您使用auth code flow获取访问令牌,则应授予委派权限,因为这是与用户交互的授权流,因此请尝试授予 Directory.Read.All delegated permissions,然后授予管理员同意以获取权限。

enter image description here