如何 'Grant Permissions' 使用 Azure Active Directory PowerShell V2

How to 'Grant Permissions' Using Azure Active Directory PowerShell V2

我已经使用 Azure Active Directory PowerShell V2 编写了我的 Azure Active Directory 应用程序的创建脚本,并尝试在我的单页应用程序 (SPA) 中使用委派权限,使用隐式流调用 API已定义应用程序角色。

我需要使用什么 PowerShell 命令来复制 Azure 门户中“应用程序设置”下的 'Grant Permissions' 按钮:

根据 Docs:

Granting explicit consent using the Grant Permissions button is currently required for single page applications (SPA) using ADAL.js, as the access token is requested without a consent prompt, which will fail if consent is not already granted.

另外,如何判断是否已授予权限?按钮总是可点击的?如果你问我,糟糕的用户体验。

此按钮实际上是在征得管理员同意。这将同意租户中的所有用户。对于您的情况,如果您想避免 Azure Portal,您可以在 SPA 而不是在 PowerShell 中强制同意。

为此,您的 SPA 应在身份验证请求上附加 &prompt=consent&prompt=admin_consent。前者应该在每次新用户第一次登录时应用,而后者你可以做一次(使用管理员帐户登录)并且它会同意所有用户。

结帐understanding Admin and User Consent