【问题标题】:Connect-ADAccount with service principal: Insufficient privileges to perform requested operation使用服务主体连接 ADAccount:权限不足,无法执行请求的操作
【发布时间】:2023-03-30 14:54:01
【问题描述】:

我需要能够在非交互模式下运行Connect-ADAccount,邀请用户加入我的 AD,为这个新用户分配一些资源权限。

所以我有:

创建了一个服务主体。

使用以下代码创建了一个证书:

Connect-AzureAD 
$Certname = Read-Host "Enter Certificate Name"
$Cert = New-SelfSignedCertificate -certstorelocation cert:\localmachine\my -dnsname $Certname -Provider “Microsoft Enhanced RSA and AES Cryptographic Provider”
$pw = ConvertTo-SecureString -String "Pazzword" -Force -AsPlainText
$thumbprint = $Cert.Thumbprint

Export-PfxCertificate -cert cert:\localMachine\my\$thumbprint -FilePath $env:USERPROFILE\Desktop\$Certname.pfx -Password $pw

Get-PfxCertificate -FilePath $env:USERPROFILE\Desktop\$Certname.pfx | Export-Certificate -FilePath 
$env:USERPROFILE\Desktop\OutputCert.crt -Type Cert

手动上传。

向我的服务主体授予所有者权限。

现在我可以运行以下代码,但它会在 New-AzureADMSInvitation 步骤中失败。

Connect-AzureAD -TenantId $ObjectId -ApplicationId  $AppId -CertificateThumbprint $thumb

New-AzureADMSInvitation -InvitedUserDisplayName $userName -InvitedUserEmailAddress $userEmail -InviteRedirectUrl 'https://portal.azure.com/' -SendInvitationMessage $true 

我不确定在这种情况下需要什么权限。

New-AzureADMSInvitation : Error occurred while executing NewAzureADMSInvitation 
Code: Unauthorized
Message: Insufficient privileges to perform requested operation by the application '00000003-0000-0000-c000-000000000000'. ControllerName=MSGraphInviteAPI, ActionName=CreateInvite [...]

【问题讨论】:

  • 您向服务主体授予了所有者权限?

标签: azure powershell


【解决方案1】:

New-AzureADMSInvitation 在后端调用Create invitation MS Graph API。

POST https://graph.microsoft.com/v1.0/invitations

使用服务主体时需要添加以下应用权限之一:

  • User.Invite.All,
  • User.ReadWrite.All,
  • Directory.ReadWrite.All

请导航到应用注册 > 您的应用 > 添加 API 权限 > Microsoft Graph API > 在应用程序权限中选择上一个。还要记住为您的租户授予管理员同意。

【讨论】:

    猜你喜欢
    • 2021-01-28
    • 2020-07-06
    • 1970-01-01
    • 2019-02-16
    • 1970-01-01
    • 1970-01-01
    • 2019-07-24
    • 2020-11-29
    • 1970-01-01
    相关资源
    最近更新 更多