Azure AD管理员通过PowerShell同意



今天,这似乎是授予OAuth同意为Azure Active Directory应用程序的管理员的唯一方法是通过Azure Portal。有什么办法可以通过PowerShell编程执行此操作?如果没有,将来是否有任何计划添加此支持?

似乎您要授予Azure Ad App的管理员同意

很容易给予该应用程序的管理员同意,我们只需要在值admin_consent的情况下添加附加参数prompt参数即可。例如,以下是请求请求给管理员同意:

https://login.microsoftonline.com/{tenant}/oauth2/authorize?
client_id=6731de76-14a6-49ae-97bc-6eba6914391e
&response_type=code
&redirect_uri=http%3A%2F%2Flocalhost%2Fmyapp%2F
&response_mode=query
&resource=https%3A%2F%2Fservice.contoso.com%2F
&state=12345
&prompt=admin_consent

您只需访问此URL即可为应用程序(6731de76-14a6-49ae-97bc-6eba6914391e)提供管理员同意。而且,如果您想通过PowerShell实现它,我们只需要通过PowerShell导航该URL即可。例如,我们可以使用Start-Process命令let,如下所示:

Start-Process -FilePath  "https://login.microsoftonline.com/{tenant}/oauth2/authorize?client_id=6731de76-14a6-49ae-97bc-6eba6914391e&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%2Fmyapp%2F&response_mode=query&resource=https%3A%2F%2Fservice.contoso.com%2F&state=12345&prompt=admin_consent"

有关OAuth协议中参数的更多详细信息,您可以参考下面的链接:

授权使用OAuth 2.0和Azure Active Directory访问Web应用程序

授予Azure AD v2.0端点的管理员同意,您可以参考下面有关Azure AD AD v2.0 Endpoint的管理员同意的链接。

使用管理员同意端点

这应该有效:

az ad app permission admin-consent --id $appId

最新更新