【问题标题】:Azure AD Admin Consent via PowerShell?通过 PowerShell 获得 Azure AD 管理员同意?
【发布时间】:2018-02-15 00:53:26
【问题描述】:

如今,作为 Azure Active Directory 应用程序的管理员授予 OAuth 同意的唯一方法似乎是通过 Azure 门户。有没有办法通过 PowerShell 以编程方式执行此操作?如果没有,是否有计划在未来添加此支持?

【问题讨论】:

  • Steve,我编写了一个 PowerShell 函数来设置 Azure AD 应用程序的一般权限(委托权限和应用程序权限)。请参阅github.com/Azure-Samples/… 我不确定这是否也会提供管理员同意。
  • 太棒了,这很有帮助。感谢您分享。
  • 您需要为委派权限创建 OAuth2PermissionGrants(consentType="AllPrincipals" 和 principalId=null),并为应用权限创建 AppRoleAssignments(在应用的服务主体上)。我相信你可以用New-AzureADServiceAppRoleAssignment 做第二个,不确定第一个是否有cmdlet。无论如何,这就是按钮的作用。
  • @juunas 您引用的命令行开关来自哪个库?我在 Azure SDK for PowerShell 中没有看到那个。

标签: azure azure-active-directory


【解决方案1】:

您似乎想为 Azure 广告应用授予 管理员同意

应用的管理员同意很容易,我们只需要添加附加参数prompt参数值为admin_consent。例如下面是一个请求去给予管理员同意:

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 command-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协议中的参数,可以参考以下链接:

Authorize access to web applications using OAuth 2.0 and Azure Active Directory

授予 Azure AD V2.0 端点的管理员同意是不同的,您可以参考下面的链接关于授予 Azure AD V2.0 端点的管理员同意。

Using the admin consent endpoint

【讨论】:

    【解决方案2】:

    这应该可行:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多