gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 00:56:21 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com