是否有与"az rest"等效的PowerShell? [英] Is there a PowerShell equivalent to "az rest"?

查看:77
本文介绍了是否有与"az rest"等效的PowerShell?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近发现了 az rest 命令,该命令使我可以执行经过身份验证的REST命令,而不必担心获取令牌.

对令牌进行解码,我们可以发现受众是正确的.

获取令牌后,您只需使用示例.

I recently discovered the az rest command, which allows me to perform authenticated REST commands, without having to worry about acquiring tokens.

https://www.codeisahighway.com/native-azure-rest-api-calls-now-available-in-azure-cli-2-0-67/

az rest --method patch --url "https://graph.microsoft.com/v1.0/users/johndoe@azuresdkteam.onmicrosoft.com" --body "{\"displayName\": \"jondoe2\"}"

Is there an equivalent in Azure Powershell? I need to do a call which is not available via any of the AzAd... cmdlets. I would imagine something like Invoke-AzRestMethod, but this does not exist.

Edit: I want to execute calls which are not available via the Azure AD Cmdlets (yet). Like using the new typed replyUrls directly, or uploading custom policies for AAD B2C (Beta API).

解决方案

There is no built-in powershell command equals az rest currently.

My workaround is to use the command below, you could simply use it to get the specific token for a specific resource with your login account/service principal, e.g. https://management.azure.com, https://graph.microsoft.com, it can also be other resources, even the app-id of your custom API in AAD.

Sample:

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

Decode the token, we can find the audience is correct.

After getting the token, you can simply use the Invoke-RestMethod to call any REST API you want, for the format, you can check this sample.

这篇关于是否有与"az rest"等效的PowerShell?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆