我熟悉在 Az CLI 中请求 token -- az account get-access-token --resource-type ms-graph | ConvertFrom-Json
但我需要从 Azure PowerShell 获取此信息。我知道您可以通过以下方式请求 REST API token
$currentAzureContext = Get-AzContext
$profileClient = New-Object Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient([Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile);
$UserToken = $profileClient.AcquireAccessToken($currentAzureContext.Subscription.TenantId).AccessToken;
但同样,我需要一个图形访问 token 。有办法做到这一点吗?
最佳答案
不确定它是否算作重复,但是我前几天得到的这个答案是我的 question也能解决你的问题。
Connect-AzAccount
$resource = "https://graph.microsoft.com"
$context = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile.DefaultContext
$Token = [Microsoft.Azure.Commands.Common.Authentication.AzureSession]::Instance.AuthenticationFactory.Authenticate($context.Account, $context.Environment, $context.Tenant.Id.ToString(), $null, [Microsoft.Azure.Commands.Common.Authentication.ShowDialog]::Never, $null, $resource).AccessToken
关于azure - 如何从 Azure PowerShell 为用户请求 Azure Graph API 访问 token ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62943573/