azure - 如何从 Azure PowerShell 为用户请求 Azure Graph API 访问令牌?
问题描述
我熟悉在 Az CLI 中请求令牌——az account get-access-token --resource-type ms-graph | ConvertFrom-Json
但我需要 Azure PowerShell 中的这个。我知道您可以通过以下方式请求 REST API 令牌
$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;
但同样,我需要一个 Graph 访问令牌。有什么办法吗?
解决方案
不确定它是否算作重复,但我前几天得到的这个答案也可以解决你的问题。
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
推荐阅读
- angular - Angular 通用服务的多个实例
- flutter - RenderFlex 孩子有非零的弹性错误/颤振
- android - 在 Android 中将多个 LiveData 对象聚合为一个 LiveData 聚合对象
- javascript - 如何按顺序处理 websocket 消息
- git - Github:从 PR 中删除添加的文件
- azure - 部署前 Azure clean $web
- reactjs - 使用自定义钩子封装 useEffect 和 AJAX 请求
- format - 如何在乳胶中漂浮长桌?
- android - 启动 geth 节点时应用程序在启动时崩溃
- architecture - 系统设计 观看直播的用户数