azure - 如何从 Azure PowerShell 为用户请求 Azure Graph API 访问 token ?

标签 azure powershell

我熟悉在 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/

相关文章:

c# - 如何在Azure API函数中返回变量并通过移动应用程序中的调用异步函数读取它

azure - 记录 Azure 上的数据库使用情况

loops - 从 Powershell 的 ForEach 中返回一个值

PowerShell:无法捕获 get-content 抛出的 UnauthorizedAccessException

sql - 提高 SQL Server 中的 Xquery 性能

azure - Azure VM 上的性能极其缓慢

azure - FineUploader 到 Azure 存储

powershell - 无法在 TFS 后生成脚本中执行 AWS Powershell 工具 cmdlet

windows - 如何使用 Powershell 'invoke-expression' 以不同用户身份运行可执行文件

Powershell脚本计算省略包含特定字符的行的行数